Project

General

Profile

Actions

Bug #11750

closed

ksh mkdir builtin doesn't honor special file permissions

Added by Alexander Pyhalov almost 2 years ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

mkdir ksh builtin misbehaves in a following way:

# /usr/bin/sh
$ export PATH=/bin
$ id 
uid=0(root) gid=0(root)
$ mkdir -m 1777 /tmp/111
$ ls -ld /tmp/111
drwxrwxrwx   2 root     root         117 Sep 26 14:44 /tmp/111
$ rmdir /tmp/111
$ /bin/mkdir -m 1777 /tmp/111
$ ls -ld /tmp/111
drwxrwxrwt   2 root     root         117 Sep 26 14:54 /tmp/111


Related issues

Related to illumos gate - Feature #13405: ksh93 update to 2012-08-01ClosedAndy Fiddaman

Actions
Actions #1

Updated by Alexander Pyhalov almost 2 years ago

  • Description updated (diff)
Actions #2

Updated by Peter Tribble almost 2 years ago

A quick look at usr/src/lib/libcmd/common/mkdir.c indicates a problem - it looks like chmod() is only called to fix up the permissions on the last entry of a hierarchy created with the -p flag, where the immediate parent doesn't exist.

To confirm this,

$ mkdir -m 1777 -p /tmp/111/222
$ ls -ld /tmp/111/222
drwxrwxrwt 2 ptribble it 117 Sep 26 21:53 /tmp/111/222

Another thing I notice is that mkdir(2) claims that the supplied mode is applied to the directory, which is clearly incorrect - special bits are stripped from the mode and need to be put back with an explicit chmod().

Actions #3

Updated by Andy Fiddaman 8 months ago

This appears to be fixed in the 2012 version of ksh which is being integrated under #13405

af@bloody:~/ksh$ echo $KSH_VERSION
Version jMP 93u+ 2012-08-01

af@bloody:~/ksh$ type mkdir
mkdir is a shell builtin version of /usr/bin/mkdir

af@bloody:~/ksh$ mkdir -m 1777 /tmp/nnn
af@bloody:~/ksh$ ls -ld /tmp/nnn
drwxrwxrwt   2 af       other        117 Jan 18 16:08 /tmp/nnn

af@bloody:~/ksh$ mkdir -m 1777 -p /tmp/ooo/ppp
drwxr-xr-x   3 af       other        177 Jan 18 16:08 /tmp/ooo
af@bloody:~/ksh$ ls -ld /tmp/ooo /tmp/ooo/ppp
drwxr-xr-x   3 af       other        177 Jan 18 16:08 /tmp/ooo
drwxrwxrwt   2 af       other        117 Jan 18 16:08 /tmp/ooo/ppp
Actions #4

Updated by Andy Fiddaman 8 months ago

Actions #5

Updated by Electric Monk 8 months ago

  • Gerrit CR set to 1175
Actions #6

Updated by Electric Monk 8 months ago

  • % Done changed from 0 to 100
  • Status changed from New to Closed

git commit b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f

commit  b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f
Author: Andy Fiddaman <omnios@citrus-it.co.uk>
Date:   2021-01-30T17:13:33.000Z

    13405 ksh93 update to 2012-08-01
    13434 sh: mishandles backslash as last character of a block of input
    11750 ksh mkdir builtin doesn't honor special file permissions
    9199 ksh93 builtin *grep -v mishandles blank lines, blows up libgcrypt-config
    6756 sh (and ksh) have issues with ${1+"$@"}
    6520 ksh: sleep could wait forever
    4860 ksh93: core in printf
    3791 /bin/sh's builtin 'rm' busted: 'rm -f' without arguments returns error
    1047 ksh overwrites child core files
    880 ksh93 coredumps on 'unset'
    499 "interrupted system call" when using "tee" builtin in ksh
    Reviewed by: Robert Mustacchi <rm@fingolfin.org>
    Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
    Reviewed by: Dominik Hassler <hadfl@omnios.org>
    Approved by: Rich Lowe <richlowe@richlowe.net>

Actions

Also available in: Atom PDF