From 5c8574b51210be53efbb488965db0b8591c8d1cf Mon Sep 17 00:00:00 2001 From: Benoit Goby Date: Tue, 14 Aug 2012 15:43:46 -0700 Subject: [PATCH] init: Fix mkdir command when using ISUID or ISGID bit On first boot, the directory is created with root:root ownership and then chowned. chown clears the ISUID and ISGID bits, so we need to chmod the directory again after chown. Change-Id: I02dfe7a19a637678256b4e7cc09e6b5431e6f11e --- init/builtins.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/init/builtins.c b/init/builtins.c index da41b8975..bb963c141 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -322,6 +322,14 @@ int do_mkdir(int nargs, char **args) if (_chown(args[1], uid, gid) < 0) { return -errno; } + + /* chown may have cleared S_ISUID and S_ISGID, chmod again */ + if (mode & (S_ISUID | S_ISGID)) { + ret = _chmod(args[1], mode); + if (ret == -1) { + return -errno; + } + } } return 0;