Re: [PATCH 9/9] sysfs: disallow world-writable files.

From: Gobinda Charan Maji
Date: Wed Apr 29 2015 - 08:24:40 EST


Rusty Russell <rusty <at> rustcorp.com.au> writes:

>
> This check was introduced in 2006 by Alexey Dobriyan (9774a1f54f173)
> for module parameters; we removed it when we unified the check into
> VERIFY_OCTAL_PERMISSIONS() as sysfs didn't have the same requirement.
> Now all those users are fixed, reintroduce it.
>
> Cc: Alexey Dobriyan <adobriyan <at> gmail.com>
> Cc: Dave Jones <davej <at> redhat.com>
> Cc: Joe Perches <joe <at> perches.com>
> Signed-off-by: Rusty Russell <rusty <at> rustcorp.com.au>
> ---
> include/linux/kernel.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 4c52907a6d8b..43e1c6a9683e 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> <at> <at> -849,5 +849,7 <at> <at> static inline void
ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
> /* User perms >= group perms >= other perms */ \
> BUILD_BUG_ON_ZERO(((perms) >> 6) < (((perms) >> 3) & 7)) + \
> BUILD_BUG_ON_ZERO((((perms) >> 3) & 7) < ((perms) & 7)) + \
> + /* Other writable? Generally considered a bad idea. */ \
> + BUILD_BUG_ON_ZERO((perms) & 2) + \
> (perms))
> #endif

Hi Rusty,

I have a small doubt about the permission restriction (User perms >= group
perms >= other perms) in VERIFY_OCTAL_PERMISSIONS(). Please Note that
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. Say for example, permission value is "0431". Here User has only
READ permission whereas Group has both WRITE and EXECUTE permission and
Other has EXECUTE permission. I guess, it is not good to give Group the
WRITE permission whereas User itself has no WRITE permission.
May be, it's better to check those three permissions bit wise rather than
as a whole.
I already had posted my query at:

http://thread.gmane.org/gmane.linux.kernel/1667095/focus=1737833

But could get any reply.

Please rethink about my point and let me know your opinion.

Thanks,
Gobinda



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/