Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2329666imm; Fri, 7 Sep 2018 14:46:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbXMn6EDCey+6fICyzbk8RwQ/ndgAAcaBwGRaZ+2mBODyDf26sX09tw1faJLnrexUeJsZ/C X-Received: by 2002:a62:ea05:: with SMTP id t5-v6mr10887580pfh.228.1536356813004; Fri, 07 Sep 2018 14:46:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536356812; cv=none; d=google.com; s=arc-20160816; b=LhIVo8AsKYRbYNxJtqINa+/PWmgq5xAYnWBOc5kxvKH/6O1LUVzJwFTXcBq6yNPz9A QeA92TtjSDGUCwjnAHooEvYtyGE/CC4gJWB3EV4ltgqzaGBicDCU/Fxdftnf2uA+Ql/T SJhOevBIspgfi7w5ok4SaPn1I1ZSDFSHEuyM96lAM6r5AnyjSIU9raytfPR/N+sJCNCY 17FDpOrgq7fIeSiDsulsOyBCFOsvM8dP/OGb84PWOgclWGNxrsvUkUcl1Ebw4lVih+bU 1DeeEt0CK/A2pdxI6/e5uG/9A1+fkVaainquXefumjwzn7NlzHPn+W+5gqRDeLNGdUW3 ru0w== 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=HsWboQ7/ixN8WlAENXzc+QvC51DSyJJCWsaJuYKxw94=; b=k7XWfaCwknZXPxlQhza68s8d1uza0I1a8CrCIoV6i0KglD13xVQlfJ91fXIytLCHij /Imwd8Y2epLlDGk+nA5UlFOvM9Pnx04KZGJxt/REexKCK0unTyCKYYHxy0hIIxBvb8wi gri/92x/cPzmrGi3ICGJPsbrKZEsKmlcyWMEwO5CtOVWtz+I8yjV3L1aJWijFcWX0ORg CzQ4G8wflusDYoU1uV2DawiIbi1LS4gQHtWG2AI7UwVJabepwOn+kOafBB+f1hwQwX8A PQmxQ3D7bgWCkL8EIvOm26LRAyqtl+zkuHMqcGCr0pF2etjRnvBpVWkHJ+naUHNlDvAK VQ5w== 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 j13-v6si10110406pfj.230.2018.09.07.14.46.37; Fri, 07 Sep 2018 14:46:52 -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 S1731026AbeIHC1m (ORCPT + 99 others); Fri, 7 Sep 2018 22:27:42 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57858 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726568AbeIHC1l (ORCPT ); Fri, 7 Sep 2018 22:27:41 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BD54F100B; Fri, 7 Sep 2018 21:44:44 +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 3.18 28/29] getxattr: use correct xattr length Date: Fri, 7 Sep 2018 23:10:49 +0200 Message-Id: <20180907210911.364844106@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907210909.523240901@linuxfoundation.org> References: <20180907210909.523240901@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 3.18-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 @@ -455,7 +455,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) {