Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2327976imm; Fri, 7 Sep 2018 14:45:00 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYGs9HLsyg1ersrPuXLc+lUD+/o0qKPVvwsWQhGcT4GDr/rOf4hqEOfAp9Q25hwtyredcNe X-Received: by 2002:a63:b914:: with SMTP id z20-v6mr10350971pge.396.1536356700406; Fri, 07 Sep 2018 14:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536356700; cv=none; d=google.com; s=arc-20160816; b=MeDKeiQOdXfMA9bxjiS8A2iXH18QLkewlsTopO6bcqoI0VEqHEN+pU1lRGEKojvrc+ prqJxc0+jgQtweli3g4lIcVxoyLQbSwvIZJlCJ7CdhhUcdLNmRJSAfj2JgWpPVOQ3AH4 0qVadufNPiivAIpA3JTT4sraGqSJ89ic0Wbjfd/q7xp/xP0nhmnEm6uEoB8didvo3wwY CKmHaonHg/wIy3/z0NqlrkojpM/nt13gItdO9jDYg2vITBxvVRpcm05XeDdqrJdAB2hT PAaJZsab+lPmGzC8AcK8eAvCxajnojPsad7dCckMHeLwKXf4RYcOmowlxNh2E8JDFpKe SqNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from; bh=aBltGZNWUChl/YmGBnu+pz0t2fqnqAC2+zhUW73cYD4=; b=tpOfRMfQfH/FeVWMeh9MAYtg6FAibY2WVnwpltzVSaUYsnRN1XRlBcfdVGCNCFQuhQ uxezDsbssTNmS/AIGJ9b7tQq+0PalbwudHCRckBE5q5Buq7kFMCJxFW3VE9qFkQPGlkt gWq4S9czqGjXGzCxBHDPVS5eSaLmn5qcTXMcut/SKz5j5Q4wRQ+uTiqHPRQJx44lKIHs 0cxnwjLmUs7nx+FNuURjBnfInXGFo43iuVs3tLFP7xHHD8TP2QqRtQH7OOQ0t1iJHBEA raiUSCiC9JWL6M3u/LCspeE3KsVKlqeXO9NZUqi5uvgJwsrSMhvziN4WokqDOjF5jLJn jXKQ== 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 k3-v6si9174061pld.6.2018.09.07.14.44.45; Fri, 07 Sep 2018 14:45:00 -0700 (PDT) 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 S1730596AbeIHCZY (ORCPT + 99 others); Fri, 7 Sep 2018 22:25:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56520 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbeIHCZX (ORCPT ); Fri, 7 Sep 2018 22:25:23 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 08070BBF; Fri, 7 Sep 2018 21:42:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Watson , Christian Brauner , Serge Hallyn , "Eric W. Biederman" Subject: [PATCH 4.4 42/47] getxattr: use correct xattr length Date: Fri, 7 Sep 2018 23:10:38 +0200 Message-Id: <20180907210908.949596504@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907210904.607934824@linuxfoundation.org> References: <20180907210904.607934824@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable 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 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 Signed-off-by: Christian Brauner Acked-by: Serge Hallyn Signed-off-by: Eric W. Biederman Signed-off-by: Greg Kroah-Hartman --- 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) {