Re: [patch] rc.d/tmp (silly mkdir usage)

diz_at_linuxpowered.com
Date: 08/02/05

  • Next message: Brooks Davis: "Re: [patch] rc.d/tmp (silly mkdir usage)"
    Date: Tue, 2 Aug 2005 11:47:19 -0500 (CDT)
    To: vd@datamax.bg
    
    

    > On Mon, Aug 01, 2005 at 11:37:05PM -0500, diz@linuxpowered.com wrote:
    >> Howdy hackers,
    >>
    >> I'm sorry for the previous patch, so here is at least one item that
    >> really
    >> bugs me that isn't obfuscation. In short, I don't see any reason to fork
    >> some process to simply "touch" a file (is a filesystem writable) when
    >> built-in shell i/o does this:
    >>
    >> --- /etc/rc.d/tmp.orig Mon Aug 1 23:20:24 2005
    >> +++ /etc/rc.d/tmp Mon Aug 1 23:22:07 2005
    >> @@ -48,8 +48,8 @@
    >> [Nn][Oo])
    >> ;;
    >> *)
    >> - if (/bin/mkdir -p /tmp/.diskless 2> /dev/null); then
    >> - rmdir /tmp/.diskless
    >> + if ( > /tmp/.diskless 2> /dev/null); then
    >> + rm /tmp/.diskless
    >> else
    >> if [ -h /tmp ]; then
    >> echo "*** /tmp is a symlink to a non-writable
    >> area!"
    >>
    >
    > The thing you suggest is bloody insecure. Just imagine some baduser
    > doing ln -s /etc/passwd /tmp/.diskless before rc.d/tmp gets executed.
    > I guess this is the reason why directory creation is used instead of
    > file creation.

    Well these notions have nothing todo with the way it works, but they are
    interesting still. I would imagine a dir could be linked too if somebody
    managed to insert a rc.d script in that was ordered sufficiently early
    enough to do the evil tasks you are thinking about. Even if mktemp(1) were
    available at this stage, I wouldn't use it here.

    >
    > I just wonder why a new shell is forked for this test. Simply
    > if /bin/mkdir -p /tmp/.diskless 2> /dev/null ; then
    > would do the same thing without forking a new shell that only executes
    > /bin/mkdir

    Let me be clear about this, the ONLY reason mkdir is used here is because
    touch is under /usr somewhere which isn't even mounted at this point
    (assuming /usr is mounted seperatly, as is the case on nfs diskless
    systems). So we are left with what is availabile in /bin, /sbin, /rescue.
    Therefore mkdir was used as a work-around. What I'm saying is this entire
    thought process is overly-engineered when the shell can simply "touch" a
    file with stdout or stderr. This is indeed the most minor of
    optimizations.

    >
    > Even we can use
    > if [ -d /tmp -a -w /tmp ] ; then
    > or (which is equivalent)
    > if [ -d /tmp ] && [ -w /tmp ] ; then
    > and save external commands (mkdir) execution and directory
    > creation/deletion at all.
    >

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Brooks Davis: "Re: [patch] rc.d/tmp (silly mkdir usage)"

    Relevant Pages

    • Re: Atheists are the biggest fools on Earth
      ... historical account of the creation of the world. ... >>> same island), it would be easier. ... >>> proteins to be sequenced for a large sample of species. ... What objective reason could you have? ...
      (talk.origins)
    • Re: US Buoyancy
      ... waivers for this very reason. ... Rowing is a POTENTIALLY risky enterprise. ... When a through-flow shell takes on even a little water, ...
      (rec.sport.rowing)
    • Re: Strange file appeared in my home directory
      ... The creation date was about four ... I quickly checked my system with the native FreeBSD tool "chkrootkit". ... >>Yesterday my internet connection went down without a particular reason. ...
      (freebsd-questions)
    • Re: In the News: Tenn. AG: No constitutional concerns with
      ... about the creation of things, ... say that science has an answer for everything? ... and will never have a scientific answer for how life started. ... We just have no reason to put one in...The simple fact is that science does ...
      (talk.origins)
    • [FUD4] Re: Decision on coom and cooa policy on eComStation
      ... >> That was part of the reason for its creation (the exclusion of various ... I've been reading a large percentage of his postings in these newsgroups ... Given the sheer number of falsehoods and wild exaggerations that Tim ...
      (comp.os.os2.misc)