Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2982581imu; Sun, 9 Dec 2018 14:15:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/VQ/OzT3MKLeRPlEWyDgznBjHO3n30o1kbrXnoyZ09Pn4ET4/aHfvaH/pu/dmlKC9oAKh/V X-Received: by 2002:a17:902:a5c3:: with SMTP id t3mr9750811plq.117.1544393702597; Sun, 09 Dec 2018 14:15:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393702; cv=none; d=google.com; s=arc-20160816; b=hnz1Dgf5R0xOFTjaHcrgHyCMxrlC//3AqXU0NWoHYudJPeW1AIpC4vHg8hGYg8ldNl AxwXLf+1YEDtNS4rADT7jgghsd0SJisMSljdne+Y00JxTftW/1iU46XiHIWoAm7V2Qpi fjyuFg1o8X/JQTC5ldjWvEAlJ6CRe9Z/pxE/W7U0h4Z0O7EIj8FfqXNYy2wUvIu6T6oN zLR5HTfWAGGVPEyK7Krm8KyIVebHQZ/kXeYVDZqvoSFPxSkk+Jr5zwxUmTXwWHSYAxUt rpbk+MIw2JNoRRUTtemrvztUoSYnR1uhCQdsxAvbAcvxcUtMHVCXPgMHj/HXOuG8MkNr 7VrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=lSRuY9c1oiIAb9kaEq5czeswiMeEhW5ayjhuzXzGeIw=; b=0i6x2FD0+KvimPZ9qAfW6axHeD54nhtllNmNao0sA8PhizZQG51eFGz0Q5gI54dNjq 6I/Lbp0/uZ5sp9fki6r+9IA/oxFORWWZfww/5lf81qyPPtmY6//+hSZBIr0OcflS2Yi1 /N81Egz5fKMxTHUsDHg3BfhN2CrQ9IbuRxNCZpCRfz65+G1S9TkXtw/FNGrq37df1csZ tqGCLMjCIiNsvg3A48n1hhlqzc27kKLik0A2OXWFIA2foLAPQZUp9m/wyWatq3TTj+Go ytkKvRVaSyw09N6+/h+DiXfR6TU5TGwQ8O9sq8BDc5+agSp59vGQOTn0MJOIFiz2QwCj J8Vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e15si8035779pgg.281.2018.12.09.14.14.47; Sun, 09 Dec 2018 14:15:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727974AbeLIWMV (ORCPT + 99 others); Sun, 9 Dec 2018 17:12:21 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:37786 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726734AbeLIWMT (ORCPT ); Sun, 9 Dec 2018 17:12:19 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW73B-0002ic-Q5; Sun, 09 Dec 2018 21:55:45 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72e-0003Qr-8j; Sun, 09 Dec 2018 21:55:12 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Serge Hallyn" , "Christian Brauner" , "Colin Watson" , "Eric W. Biederman" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 157/328] getxattr: use correct xattr length In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Christian Brauner 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 #include #include #include #include #include #include /* 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 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 Signed-off-by: Christian Brauner Acked-by: Serge Hallyn Signed-off-by: Eric W. Biederman Signed-off-by: Ben Hutchings --- fs/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/xattr.c +++ b/fs/xattr.c @@ -466,7 +466,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) {