From: Chris Wright <chrisw@sous-sol.org>
To: linux-kernel@vger.kernel.org, stable@kernel.org, jejb@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
"Theodore Ts'o" <tytso@mit.edu>,
Randy Dunlap <rdunlap@xenotime.net>,
Dave Jones <davej@redhat.com>,
Chuck Wolber <chuckw@quantumlinux.com>,
Chris Wedgwood <reviews@ml.cw.f00f.org>,
Michael Krufky <mkrufky@linuxtv.org>,
Chuck Ebbert <cebbert@redhat.com>,
Domenico Andreoli <cavokz@gmail.com>,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, "Andrew G. Morgan" <morgan@kernel.org>,
"Serge E. Hallyn" <serue@us.ibm.com>,
Bojan Smojver <bojan@rexursive.com>
Subject: [patch 49/50] capabilities: remain source compatible with 32-bit raw legacy capability support.
Date: Fri, 06 Jun 2008 18:03:04 -0700 [thread overview]
Message-ID: <20080607010636.816195762@sous-sol.org> (raw)
In-Reply-To: <20080607010215.358296706@sous-sol.org>
[-- Attachment #1: capabilities-remain-source-compatible-with-32-bit-raw-legacy-capability-support.patch --]
[-- Type: text/plain, Size: 9656 bytes --]
-stable review patch. If anyone has any objections, please let us know.
---------------------
From: Andrew G. Morgan <morgan@kernel.org>
upstream commit: ca05a99a54db1db5bca72eccb5866d2a86f8517f
Source code out there hard-codes a notion of what the
_LINUX_CAPABILITY_VERSION #define means in terms of the semantics of the
raw capability system calls capget() and capset(). Its unfortunate, but
true.
Since the confusing header file has been in a released kernel, there is
software that is erroneously using 64-bit capabilities with the semantics
of 32-bit compatibilities. These recently compiled programs may suffer
corruption of their memory when sys_getcap() overwrites more memory than
they are coded to expect, and the raising of added capabilities when using
sys_capset().
As such, this patch does a number of things to clean up the situation
for all. It
1. forces the _LINUX_CAPABILITY_VERSION define to always retain its
legacy value.
2. adopts a new #define strategy for the kernel's internal
implementation of the preferred magic.
3. deprecates v2 capability magic in favor of a new (v3) magic
number. The functionality of v3 is entirely equivalent to v2,
the only difference being that the v2 magic causes the kernel
to log a "deprecated" warning so the admin can find applications
that may be using v2 inappropriately.
[User space code continues to be encouraged to use the libcap API which
protects the application from details like this. libcap-2.10 is the first
to support v3 capabilities.]
Fixes issue reported in https://bugzilla.redhat.com/show_bug.cgi?id=447518.
Thanks to Bojan Smojver for the report.
[akpm@linux-foundation.org: s/depreciate/deprecate/g]
[akpm@linux-foundation.org: be robust about put_user size]
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
Cc: Serge E. Hallyn <serue@us.ibm.com>
Cc: Bojan Smojver <bojan@rexursive.com>
Cc: stable@kernel.org
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
---
fs/proc/array.c | 2
include/linux/capability.h | 29 ++++++++---
kernel/capability.c | 111 +++++++++++++++++++++++++++++----------------
3 files changed, 95 insertions(+), 47 deletions(-)
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -287,7 +287,7 @@ static void render_cap_t(struct seq_file
seq_printf(m, "%s", header);
CAP_FOR_EACH_U32(__capi) {
seq_printf(m, "%08x",
- a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
+ a->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
}
seq_printf(m, "\n");
}
--- a/include/linux/capability.h
+++ b/include/linux/capability.h
@@ -31,11 +31,11 @@ struct task_struct;
#define _LINUX_CAPABILITY_VERSION_1 0x19980330
#define _LINUX_CAPABILITY_U32S_1 1
-#define _LINUX_CAPABILITY_VERSION_2 0x20071026
+#define _LINUX_CAPABILITY_VERSION_2 0x20071026 /* deprecated - use v3 */
#define _LINUX_CAPABILITY_U32S_2 2
-#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_2
-#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_2
+#define _LINUX_CAPABILITY_VERSION_3 0x20080522
+#define _LINUX_CAPABILITY_U32S_3 2
typedef struct __user_cap_header_struct {
__u32 version;
@@ -77,10 +77,23 @@ struct vfs_cap_data {
} data[VFS_CAP_U32];
};
-#ifdef __KERNEL__
+#ifndef __KERNEL__
+
+/*
+ * Backwardly compatible definition for source code - trapped in a
+ * 32-bit world. If you find you need this, please consider using
+ * libcap to untrap yourself...
+ */
+#define _LINUX_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_1
+#define _LINUX_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_1
+
+#else
+
+#define _KERNEL_CAPABILITY_VERSION _LINUX_CAPABILITY_VERSION_3
+#define _KERNEL_CAPABILITY_U32S _LINUX_CAPABILITY_U32S_3
typedef struct kernel_cap_struct {
- __u32 cap[_LINUX_CAPABILITY_U32S];
+ __u32 cap[_KERNEL_CAPABILITY_U32S];
} kernel_cap_t;
#define _USER_CAP_HEADER_SIZE (sizeof(struct __user_cap_header_struct))
@@ -350,7 +363,7 @@ typedef struct kernel_cap_struct {
*/
#define CAP_FOR_EACH_U32(__capi) \
- for (__capi = 0; __capi < _LINUX_CAPABILITY_U32S; ++__capi)
+ for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi)
# define CAP_FS_MASK_B0 (CAP_TO_MASK(CAP_CHOWN) \
| CAP_TO_MASK(CAP_DAC_OVERRIDE) \
@@ -360,7 +373,7 @@ typedef struct kernel_cap_struct {
# define CAP_FS_MASK_B1 (CAP_TO_MASK(CAP_MAC_OVERRIDE))
-#if _LINUX_CAPABILITY_U32S != 2
+#if _KERNEL_CAPABILITY_U32S != 2
# error Fix up hand-coded capability macro initializers
#else /* HAND-CODED capability initializers */
@@ -371,7 +384,7 @@ typedef struct kernel_cap_struct {
# define CAP_NFSD_SET {{ CAP_FS_MASK_B0|CAP_TO_MASK(CAP_SYS_RESOURCE), \
CAP_FS_MASK_B1 } }
-#endif /* _LINUX_CAPABILITY_U32S != 2 */
+#endif /* _KERNEL_CAPABILITY_U32S != 2 */
#define CAP_INIT_INH_SET CAP_EMPTY_SET
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -53,6 +53,69 @@ static void warn_legacy_capability_use(v
}
/*
+ * Version 2 capabilities worked fine, but the linux/capability.h file
+ * that accompanied their introduction encouraged their use without
+ * the necessary user-space source code changes. As such, we have
+ * created a version 3 with equivalent functionality to version 2, but
+ * with a header change to protect legacy source code from using
+ * version 2 when it wanted to use version 1. If your system has code
+ * that trips the following warning, it is using version 2 specific
+ * capabilities and may be doing so insecurely.
+ *
+ * The remedy is to either upgrade your version of libcap (to 2.10+,
+ * if the application is linked against it), or recompile your
+ * application with modern kernel headers and this warning will go
+ * away.
+ */
+
+static void warn_deprecated_v2(void)
+{
+ static int warned;
+
+ if (!warned) {
+ char name[sizeof(current->comm)];
+
+ printk(KERN_INFO "warning: `%s' uses deprecated v2"
+ " capabilities in a way that may be insecure.\n",
+ get_task_comm(name, current));
+ warned = 1;
+ }
+}
+
+/*
+ * Version check. Return the number of u32s in each capability flag
+ * array, or a negative value on error.
+ */
+static int cap_validate_magic(cap_user_header_t header, unsigned *tocopy)
+{
+ __u32 version;
+
+ if (get_user(version, &header->version))
+ return -EFAULT;
+
+ switch (version) {
+ case _LINUX_CAPABILITY_VERSION_1:
+ warn_legacy_capability_use();
+ *tocopy = _LINUX_CAPABILITY_U32S_1;
+ break;
+ case _LINUX_CAPABILITY_VERSION_2:
+ warn_deprecated_v2();
+ /*
+ * fall through - v3 is otherwise equivalent to v2.
+ */
+ case _LINUX_CAPABILITY_VERSION_3:
+ *tocopy = _LINUX_CAPABILITY_U32S_3;
+ break;
+ default:
+ if (put_user((u32)_KERNEL_CAPABILITY_VERSION, &header->version))
+ return -EFAULT;
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/*
* For sys_getproccap() and sys_setproccap(), any of the three
* capability set pointers may be NULL -- indicating that that set is
* uninteresting and/or not to be changed.
@@ -71,27 +134,13 @@ asmlinkage long sys_capget(cap_user_head
{
int ret = 0;
pid_t pid;
- __u32 version;
struct task_struct *target;
unsigned tocopy;
kernel_cap_t pE, pI, pP;
- if (get_user(version, &header->version))
- return -EFAULT;
-
- switch (version) {
- case _LINUX_CAPABILITY_VERSION_1:
- warn_legacy_capability_use();
- tocopy = _LINUX_CAPABILITY_U32S_1;
- break;
- case _LINUX_CAPABILITY_VERSION_2:
- tocopy = _LINUX_CAPABILITY_U32S_2;
- break;
- default:
- if (put_user(_LINUX_CAPABILITY_VERSION, &header->version))
- return -EFAULT;
- return -EINVAL;
- }
+ ret = cap_validate_magic(header, &tocopy);
+ if (ret != 0)
+ return ret;
if (get_user(pid, &header->pid))
return -EFAULT;
@@ -118,7 +167,7 @@ out:
spin_unlock(&task_capability_lock);
if (!ret) {
- struct __user_cap_data_struct kdata[_LINUX_CAPABILITY_U32S];
+ struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S];
unsigned i;
for (i = 0; i < tocopy; i++) {
@@ -128,7 +177,7 @@ out:
}
/*
- * Note, in the case, tocopy < _LINUX_CAPABILITY_U32S,
+ * Note, in the case, tocopy < _KERNEL_CAPABILITY_U32S,
* we silently drop the upper capabilities here. This
* has the effect of making older libcap
* implementations implicitly drop upper capability
@@ -240,30 +289,16 @@ static inline int cap_set_all(kernel_cap
*/
asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)
{
- struct __user_cap_data_struct kdata[_LINUX_CAPABILITY_U32S];
+ struct __user_cap_data_struct kdata[_KERNEL_CAPABILITY_U32S];
unsigned i, tocopy;
kernel_cap_t inheritable, permitted, effective;
- __u32 version;
struct task_struct *target;
int ret;
pid_t pid;
- if (get_user(version, &header->version))
- return -EFAULT;
-
- switch (version) {
- case _LINUX_CAPABILITY_VERSION_1:
- warn_legacy_capability_use();
- tocopy = _LINUX_CAPABILITY_U32S_1;
- break;
- case _LINUX_CAPABILITY_VERSION_2:
- tocopy = _LINUX_CAPABILITY_U32S_2;
- break;
- default:
- if (put_user(_LINUX_CAPABILITY_VERSION, &header->version))
- return -EFAULT;
- return -EINVAL;
- }
+ ret = cap_validate_magic(header, &tocopy);
+ if (ret != 0)
+ return ret;
if (get_user(pid, &header->pid))
return -EFAULT;
@@ -281,7 +316,7 @@ asmlinkage long sys_capset(cap_user_head
permitted.cap[i] = kdata[i].permitted;
inheritable.cap[i] = kdata[i].inheritable;
}
- while (i < _LINUX_CAPABILITY_U32S) {
+ while (i < _KERNEL_CAPABILITY_U32S) {
effective.cap[i] = 0;
permitted.cap[i] = 0;
inheritable.cap[i] = 0;
--
next prev parent reply other threads:[~2008-06-07 1:32 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-07 1:02 [patch 00/50] 2.6.25.6 -stable review Chris Wright
2008-06-07 1:02 ` [patch 01/50] block: do_mounts - accept root=<non-existant partition> Chris Wright
2008-06-09 13:38 ` Adrian Bunk
2008-06-09 16:48 ` Chris Wright
2008-06-07 1:02 ` [patch 02/50] POWERPC Bolt in SLB entry for kernel stack on secondary cpus Chris Wright
2008-06-07 1:02 ` [patch 03/50] USB: remove PICDEM FS USB demo (04d8:000c) device from ldusb Chris Wright
2008-06-07 1:02 ` [patch 04/50] USB: unusual_devs: Add support for GI 0401 SD-Card interface Chris Wright
2008-06-07 1:02 ` [patch 05/50] USB: option: add new Dell 5520 HSDPA variant Chris Wright
2008-06-07 1:02 ` [patch 06/50] USB: add Zoom Telephonics Model 3095F V.92 USB Mini External modem to cdc-acm Chris Wright
2008-06-07 1:02 ` [patch 07/50] USB: do not handle device 1410:5010 in option driver Chris Wright
2008-06-07 1:02 ` [patch 08/50] USB: add Telstra NextG CDMA id to " Chris Wright
2008-06-07 1:02 ` [patch 09/50] ext3/4: fix uninitialized bs in ext3/4_xattr_set_handle() Chris Wright
2008-06-07 1:02 ` [patch 10/50] libata: force hardreset if link is in powersave mode Chris Wright
2008-06-07 1:27 ` Linus Torvalds
2008-06-07 1:57 ` [stable] " Greg KH
2008-06-07 16:51 ` Linus Torvalds
2008-06-07 3:14 ` Jeff Garzik
2008-06-07 1:02 ` [patch 11/50] memory_hotplug: always initialize pageblock bitmap Chris Wright
2008-06-07 1:02 ` [patch 12/50] USB: fix build errors in ohci-omap.c and ohci-sm501.c Chris Wright
2008-06-07 1:02 ` [patch 13/50] i2c-nforce2: Disable the second SMBus channel on the DFI Lanparty NF4 Expert Chris Wright
2008-06-07 1:02 ` [patch 14/50] i2c/max6875: Really prevent 24RF08 corruption Chris Wright
2008-06-07 1:02 ` [patch 15/50] x86: user_regset_view table fix for ia32 on 64-bit Chris Wright
2008-06-07 1:02 ` [patch 16/50] i386: fix asm constraint in do_IRQ() Chris Wright
2008-06-07 1:02 ` [patch 17/50] CIFS: Fix UNC path prefix on QueryUnixPathInfo to have correct slash Chris Wright
2008-06-07 1:02 ` [patch 18/50] USB: add TELIT HDSPA UC864-E modem to option driver Chris Wright
2008-06-07 1:02 ` [patch 19/50] usb-serial: Use ftdi_sio driver for RATOC REX-USB60F Chris Wright
2008-06-07 1:02 ` [patch 20/50] cgroups: remove node_ prefix_from ns subsystem Chris Wright
2008-06-07 1:02 ` [patch 21/50] brd: dont show ramdisks in /proc/partitions Chris Wright
2008-06-07 21:51 ` H. Peter Anvin
2008-06-09 17:08 ` [stable] " Chris Wright
2008-06-09 19:49 ` Willy Tarreau
2008-06-09 20:28 ` H. Peter Anvin
2008-06-07 1:02 ` [patch 22/50] types.h: dont expose struct ustat to userspace Chris Wright
2008-06-07 1:02 ` [patch 23/50] x86: dont read maxlvt before checking if APIC is mapped Chris Wright
2008-06-07 1:02 ` [patch 24/50] IPoIB: Test for NULL broadcast object in ipiob_mcast_join_finish() Chris Wright
2008-06-07 1:02 ` [patch 25/50] x86: fix setup of cyc2ns in tsc_64.c Chris Wright
2008-06-07 1:02 ` [patch 26/50] x86: if we cannot calibrate the TSC, we panic Chris Wright
2008-06-07 1:02 ` [patch 27/50] x86: distangle user disabled TSC from unstable Chris Wright
2008-06-07 1:02 ` [patch 28/50] x86: disable TSC for sched_clock() when calibration failed Chris Wright
2008-06-07 1:02 ` [patch 29/50] XFS: Fix memory corruption with small buffer reads Chris Wright
2008-06-07 1:02 ` [patch 30/50] x86: prevent PGE flush from interruption/preemption Chris Wright
2008-06-07 1:02 ` [patch 31/50] Revert "PCI: remove default PCI expansion ROM memory allocation" Chris Wright
2008-06-07 1:02 ` [patch 32/50] PS3: gelic: fix memory leak Chris Wright
2008-06-07 1:02 ` [patch 33/50] netfilter: xt_iprange: module aliases for xt_iprange Chris Wright
2008-06-07 1:02 ` [patch 34/50] HID: split Numlock emulation quirk from HID_QUIRK_APPLE_HAS_FN Chris Wright
2008-06-07 1:02 ` [patch 35/50] CPUFREQ: Make acpi-cpufreq more robust against BIOS freq changes behind our back Chris Wright
2008-06-07 1:02 ` [patch 36/50] x86, fpu: fix CONFIG_PREEMPT=y corruption of applications FPU stack Chris Wright
2008-06-07 1:02 ` [patch 37/50] netfilter: nf_conntrack_expect: fix error path unwind in nf_conntrack_expect_init() Chris Wright
2008-06-07 1:02 ` [patch 38/50] netfilter: xt_connlimit: fix accouning when receive RST packet in ESTABLISHED state Chris Wright
2008-06-07 1:02 ` [patch 39/50] netfilter: nf_conntrack_ipv6: fix inconsistent lock state in nf_ct_frag6_gather() Chris Wright
2008-06-07 1:02 ` [patch 40/50] atl1: fix 4G memory corruption bug Chris Wright
2008-06-07 1:02 ` [patch 41/50] Smack: fuse mount hang fix Chris Wright
2008-06-07 1:02 ` [patch 42/50] proc: calculate the correct /proc/<pid> link count Chris Wright
2008-06-07 1:02 ` [patch 43/50] pagemap: fix bug in add_to_pagemap, require aligned-length reads of /proc/pid/pagemap Chris Wright
2008-06-07 1:02 ` [patch 44/50] brk: make sys_brk() honor COMPAT_BRK when computing lower bound Chris Wright
2008-06-07 1:03 ` [patch 45/50] eCryptfs: remove unnecessary page decrypt call Chris Wright
2008-06-07 1:03 ` [patch 46/50] md: do not compute parity unless it is on a failed drive Chris Wright
2008-06-07 1:03 ` [patch 47/50] md: fix uninitialized use of mddev->recovery_wait Chris Wright
2008-06-07 1:03 ` [patch 48/50] md: fix prexor vs sync_request race Chris Wright
2008-06-07 1:03 ` Chris Wright [this message]
2008-06-07 1:03 ` [patch 50/50] cpufreq: fix null object access on Transmeta CPU Chris Wright
2008-06-07 3:49 ` [patch 00/50] 2.6.25.6 -stable review Hugh Dickins
2008-06-07 4:24 ` [stable] " Chris Wright
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080607010636.816195762@sous-sol.org \
--to=chrisw@sous-sol.org \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=bojan@rexursive.com \
--cc=cavokz@gmail.com \
--cc=cebbert@redhat.com \
--cc=chuckw@quantumlinux.com \
--cc=davej@redhat.com \
--cc=jejb@kernel.org \
--cc=jmforbes@linuxtx.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkrufky@linuxtv.org \
--cc=morgan@kernel.org \
--cc=rdunlap@xenotime.net \
--cc=reviews@ml.cw.f00f.org \
--cc=serue@us.ibm.com \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=zwane@arm.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®