Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

define convenient securebits masks for prctl users (v2)

Hi James, would you mind taking the following into
security-testing?

The securebits are used by passing them to prctl with the
PR_{S,G}ET_SECUREBITS commands. But the defines must be
shifted to be used in prctl, which begs to be confused and
misused by userspace. So define some more convenient
values for userspace to specify. This way userspace does

prctl(PR_SET_SECUREBITS, SECBIT_NOROOT);

instead of

prctl(PR_SET_SECUREBITS, 1 << SECURE_NOROOT);

(Thanks to Michael for the idea)

This patch also adds include/linux/securebits to the installed headers.
Then perhaps it can be included by glibc's sys/prctl.h.

Changelog:
Oct 29: Stephen Rothwell points out that issecure can
be under __KERNEL__.
Oct 14: (Suggestions by Michael Kerrisk):
1. spell out SETUID in SECBIT_NO_SETUID*
2. SECBIT_X_LOCKED does not imply SECBIT_X
3. add definitions for keepcaps
Oct 14: As suggested by Michael Kerrisk, don't
use SB_* as that convention is already in
use. Use SECBIT_ prefix instead.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Acked-by: Andrew G. Morgan <morgan@kernel.org>
Acked-by: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Ulrich Drepper <drepper@redhat.com>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>

authored by

Serge E. Hallyn and committed by
James Morris
5975c725 ff76ec18

+19 -6
+1
include/linux/Kbuild
··· 329 329 unifdef-y += sched.h 330 330 unifdef-y += screen_info.h 331 331 unifdef-y += sdla.h 332 + unifdef-y += securebits.h 332 333 unifdef-y += selinux_netlink.h 333 334 unifdef-y += sem.h 334 335 unifdef-y += serial_core.h
+18 -6
include/linux/securebits.h
··· 1 1 #ifndef _LINUX_SECUREBITS_H 2 2 #define _LINUX_SECUREBITS_H 1 3 3 4 + /* Each securesetting is implemented using two bits. One bit specifies 5 + whether the setting is on or off. The other bit specify whether the 6 + setting is locked or not. A setting which is locked cannot be 7 + changed from user-level. */ 8 + #define issecure_mask(X) (1 << (X)) 9 + #ifdef __KERNEL__ 10 + #define issecure(X) (issecure_mask(X) & current_cred_xxx(securebits)) 11 + #endif 12 + 4 13 #define SECUREBITS_DEFAULT 0x00000000 5 14 6 15 /* When set UID 0 has no special privileges. When unset, we support ··· 21 12 #define SECURE_NOROOT 0 22 13 #define SECURE_NOROOT_LOCKED 1 /* make bit-0 immutable */ 23 14 15 + #define SECBIT_NOROOT (issecure_mask(SECURE_NOROOT)) 16 + #define SECBIT_NOROOT_LOCKED (issecure_mask(SECURE_NOROOT_LOCKED)) 17 + 24 18 /* When set, setuid to/from uid 0 does not trigger capability-"fixup". 25 19 When unset, to provide compatiblility with old programs relying on 26 20 set*uid to gain/lose privilege, transitions to/from uid 0 cause 27 21 capabilities to be gained/lost. */ 28 22 #define SECURE_NO_SETUID_FIXUP 2 29 23 #define SECURE_NO_SETUID_FIXUP_LOCKED 3 /* make bit-2 immutable */ 24 + 25 + #define SECBIT_NO_SETUID_FIXUP (issecure_mask(SECURE_NO_SETUID_FIXUP)) 26 + #define SECBIT_NO_SETUID_FIXUP_LOCKED \ 27 + (issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED)) 30 28 31 29 /* When set, a process can retain its capabilities even after 32 30 transitioning to a non-root user (the set-uid fixup suppressed by ··· 43 27 #define SECURE_KEEP_CAPS 4 44 28 #define SECURE_KEEP_CAPS_LOCKED 5 /* make bit-4 immutable */ 45 29 46 - /* Each securesetting is implemented using two bits. One bit specifies 47 - whether the setting is on or off. The other bit specify whether the 48 - setting is locked or not. A setting which is locked cannot be 49 - changed from user-level. */ 50 - #define issecure_mask(X) (1 << (X)) 51 - #define issecure(X) (issecure_mask(X) & current_cred_xxx(securebits)) 30 + #define SECBIT_KEEP_CAPS (issecure_mask(SECURE_KEEP_CAPS)) 31 + #define SECBIT_KEEP_CAPS_LOCKED (issecure_mask(SECURE_KEEP_CAPS_LOCKED)) 52 32 53 33 #define SECURE_ALL_BITS (issecure_mask(SECURE_NOROOT) | \ 54 34 issecure_mask(SECURE_NO_SETUID_FIXUP) | \