Skip to content

Commit 28b8d0c

Browse files
Gobinda Charan Majirustyrussell
authored andcommitted
sysfs: tightened sysfs permission checks
There were some inconsistency in restriction to VERIFY_OCTAL_PERMISSIONS(). Previously the test was "User perms >= group perms >= other perms". The permission field of User, Group or Other consists of three bits. LSB is EXECUTE permission, MSB is READ permission and the middle bit is WRITE permission. But logically WRITE is "more privileged" than READ. Say for example, permission value is "0430". Here User has only READ permission whereas Group has both WRITE and EXECUTE permission. So, the checks could be tightened and the tests are separated to USER_READABLE >= GROUP_READABLE >= OTHER_READABLE, USER_WRITABLE >= GROUP_WRITABLE and OTHER_WRITABLE is not permitted. Signed-off-by: Gobinda Charan Maji <gobinda.cemk07@gmail.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 4f66654 commit 28b8d0c

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎include/linux/kernel.h‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,15 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
818818
#endif
819819

820820
/* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */
821-
#define VERIFY_OCTAL_PERMISSIONS(perms) \
822-
(BUILD_BUG_ON_ZERO((perms) < 0) + \
823-
BUILD_BUG_ON_ZERO((perms) > 0777) + \
824-
/* User perms >= group perms >= other perms */ \
825-
BUILD_BUG_ON_ZERO(((perms) >> 6) < (((perms) >> 3) & 7)) + \
826-
BUILD_BUG_ON_ZERO((((perms) >> 3) & 7) < ((perms) & 7)) + \
827-
/* Other writable? Generally considered a bad idea. */ \
828-
BUILD_BUG_ON_ZERO((perms) & 2) + \
821+
#define VERIFY_OCTAL_PERMISSIONS(perms) \
822+
(BUILD_BUG_ON_ZERO((perms) < 0) + \
823+
BUILD_BUG_ON_ZERO((perms) > 0777) + \
824+
/* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */ \
825+
BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) + \
826+
BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) + \
827+
/* USER_WRITABLE >= GROUP_WRITABLE */ \
828+
BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) + \
829+
/* OTHER_WRITABLE? Generally considered a bad idea. */ \
830+
BUILD_BUG_ON_ZERO((perms) & 2) + \
829831
(perms))
830832
#endif

0 commit comments

Comments
 (0)