From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Colin Watson <cjwatson@ubuntu.com>,
Christian Brauner <christian@brauner.io>,
Serge Hallyn <serge@hallyn.com>,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH 4.4 42/47] getxattr: use correct xattr length
Date: Fri, 7 Sep 2018 23:10:38 +0200 [thread overview]
Message-ID: <20180907210908.949596504@linuxfoundation.org> (raw)
In-Reply-To: <20180907210904.607934824@linuxfoundation.org>
4.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <christian@brauner.io>
commit 82c9a927bc5df6e06b72d206d24a9d10cced4eb5 upstream.
When running in a container with a user namespace, if you call getxattr
with name = "system.posix_acl_access" and size % 8 != 4, then getxattr
silently skips the user namespace fixup that it normally does resulting in
un-fixed-up data being returned.
This is caused by posix_acl_fix_xattr_to_user() being passed the total
buffer size and not the actual size of the xattr as returned by
vfs_getxattr().
This commit passes the actual length of the xattr as returned by
vfs_getxattr() down.
A reproducer for the issue is:
touch acl_posix
setfacl -m user:0:rwx acl_posix
and the compile:
#define _GNU_SOURCE
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <attr/xattr.h>
/* Run in user namespace with nsuid 0 mapped to uid != 0 on the host. */
int main(int argc, void **argv)
{
ssize_t ret1, ret2;
char buf1[128], buf2[132];
int fret = EXIT_SUCCESS;
char *file;
if (argc < 2) {
fprintf(stderr,
"Please specify a file with "
"\"system.posix_acl_access\" permissions set\n");
_exit(EXIT_FAILURE);
}
file = argv[1];
ret1 = getxattr(file, "system.posix_acl_access",
buf1, sizeof(buf1));
if (ret1 < 0) {
fprintf(stderr, "%s - Failed to retrieve "
"\"system.posix_acl_access\" "
"from \"%s\"\n", strerror(errno), file);
_exit(EXIT_FAILURE);
}
ret2 = getxattr(file, "system.posix_acl_access",
buf2, sizeof(buf2));
if (ret2 < 0) {
fprintf(stderr, "%s - Failed to retrieve "
"\"system.posix_acl_access\" "
"from \"%s\"\n", strerror(errno), file);
_exit(EXIT_FAILURE);
}
if (ret1 != ret2) {
fprintf(stderr, "The value of \"system.posix_acl_"
"access\" for file \"%s\" changed "
"between two successive calls\n", file);
_exit(EXIT_FAILURE);
}
for (ssize_t i = 0; i < ret2; i++) {
if (buf1[i] == buf2[i])
continue;
fprintf(stderr,
"Unexpected different in byte %zd: "
"%02x != %02x\n", i, buf1[i], buf2[i]);
fret = EXIT_FAILURE;
}
if (fret == EXIT_SUCCESS)
fprintf(stderr, "Test passed\n");
else
fprintf(stderr, "Test failed\n");
_exit(fret);
}
and run:
./tester acl_posix
On a non-fixed up kernel this should return something like:
root@c1:/# ./t
Unexpected different in byte 16: ffffffa0 != 00
Unexpected different in byte 17: ffffff86 != 00
Unexpected different in byte 18: 01 != 00
and on a fixed kernel:
root@c1:~# ./t
Test passed
Cc: stable@vger.kernel.org
Fixes: 2f6f0654ab61 ("userns: Convert vfs posix_acl support to use kuids and kgids")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=199945
Reported-by: Colin Watson <cjwatson@ubuntu.com>
Signed-off-by: Christian Brauner <christian@brauner.io>
Acked-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/xattr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -453,7 +453,7 @@ getxattr(struct dentry *d, const char __
if (error > 0) {
if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
(strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
- posix_acl_fix_xattr_to_user(kvalue, size);
+ posix_acl_fix_xattr_to_user(kvalue, error);
if (size && copy_to_user(value, kvalue, error))
error = -EFAULT;
} else if (error == -ERANGE && size >= XATTR_SIZE_MAX) {
next prev parent reply other threads:[~2018-09-08 2:25 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-07 21:09 [PATCH 4.4 00/47] 4.4.155-stable review Greg Kroah-Hartman
2018-09-07 21:09 ` [PATCH 4.4 01/47] net: 6lowpan: fix reserved space for single frames Greg Kroah-Hartman
2018-09-07 21:09 ` [PATCH 4.4 02/47] net: mac802154: tx: expand tailroom if necessary Greg Kroah-Hartman
2018-09-07 21:09 ` [PATCH 4.4 03/47] 9p/net: Fix zero-copy path in the 9p virtio transport Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 04/47] net: lan78xx: Fix misplaced tasklet_schedule() call Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 05/47] spi: davinci: fix a NULL pointer dereference Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 06/47] drm/i915/userptr: reject zero user_size Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 07/47] powerpc/fadump: handle crash memory ranges array index overflow Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 08/47] powerpc/pseries: Fix endianness while restoring of r3 in MCE handler Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 09/47] fs/9p/xattr.c: catch the error of p9_client_clunk when setting xattr failed Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 10/47] 9p/virtio: fix off-by-one error in sg list bounds check Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 11/47] net/9p/client.c: version pointer uninitialized Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 12/47] net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree() Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 13/47] x86/mm/pat: Fix L1TF stable backport for CPA, 2nd call Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 14/47] dm cache metadata: save in-core policy_hint_size to on-disk superblock Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 15/47] iio: ad9523: Fix displayed phase Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 16/47] iio: ad9523: Fix return value for ad952x_store() Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 17/47] vmw_balloon: fix inflation of 64-bit GFNs Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 18/47] vmw_balloon: do not use 2MB without batching Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 19/47] vmw_balloon: VMCI_DOORBELL_SET does not check status Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 20/47] vmw_balloon: fix VMCI use when balloon built into kernel Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 21/47] tracing: Do not call start/stop() functions when tracing_on does not change Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 22/47] tracing/blktrace: Fix to allow setting same value Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 23/47] kthread, tracing: Dont expose half-written comm when creating kthreads Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 24/47] uprobes: Use synchronize_rcu() not synchronize_sched() Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 25/47] 9p: fix multiple NULL-pointer-dereferences Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 26/47] PM / sleep: wakeup: Fix build error caused by missing SRCU support Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 27/47] pnfs/blocklayout: off by one in bl_map_stripe() Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 28/47] ARM: tegra: Fix Tegra30 Cardhu PCA954x reset Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 29/47] mm/tlb: Remove tlb_remove_table() non-concurrent condition Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 30/47] iommu/vt-d: Add definitions for PFSID Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 31/47] iommu/vt-d: Fix dev iotlb pfsid use Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 32/47] osf_getdomainname(): use copy_to_user() Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 33/47] sys: dont hold uts_sem while accessing userspace memory Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 34/47] userns: move user access out of the mutex Greg Kroah-Hartman
2018-09-09 3:56 ` Rafael David Tinoco
2018-09-09 9:03 ` Greg KH
2018-09-09 9:16 ` Greg KH
2018-09-09 9:29 ` Greg KH
2018-09-07 21:10 ` [PATCH 4.4 35/47] ubifs: Fix memory leak in lprobs self-check Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 36/47] Revert "UBIFS: Fix potential integer overflow in allocation" Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 37/47] ubifs: Check data node size before truncate Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 38/47] ubifs: Fix synced_i_size calculation for xattr inodes Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 39/47] pwm: tiehrpwm: Fix disabling of output of PWMs Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 40/47] fb: fix lost console when the user unplugs a USB adapter Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 41/47] udlfb: set optimal write delay Greg Kroah-Hartman
2018-09-07 21:10 ` Greg Kroah-Hartman [this message]
2018-09-07 21:10 ` [PATCH 4.4 43/47] bcache: release dc->writeback_lock properly in bch_writeback_thread() Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 44/47] perf auxtrace: Fix queue resize Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 45/47] fs/quota: Fix spectre gadget in do_quotactl Greg Kroah-Hartman
2018-09-07 21:10 ` [PATCH 4.4 46/47] x86/io: add interface to reserve io memtype for a resource range. (v1.1) Greg Kroah-Hartman
2018-09-07 22:39 ` [PATCH 4.4 00/47] 4.4.155-stable review Nathan Chancellor
2018-09-08 21:13 ` Guenter Roeck
2018-09-09 9:01 ` Greg Kroah-Hartman
2018-09-09 15:52 ` Guenter Roeck
2018-09-09 4:52 ` Naresh Kamboju
2018-09-09 9:17 ` Greg Kroah-Hartman
2018-09-10 1:27 ` Dan Rue
2018-09-10 15:01 ` Shuah Khan
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=20180907210908.949596504@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=christian@brauner.io \
--cc=cjwatson@ubuntu.com \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stable@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).