From patchwork Wed Oct 26 17:10:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9397767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C204560234 for ; Wed, 26 Oct 2016 17:13:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BA352893C for ; Wed, 26 Oct 2016 17:12:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F9C628B26; Wed, 26 Oct 2016 17:12:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2CB62893C for ; Wed, 26 Oct 2016 17:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754944AbcJZRLL (ORCPT ); Wed, 26 Oct 2016 13:11:11 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36421 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751271AbcJZRLK (ORCPT ); Wed, 26 Oct 2016 13:11:10 -0400 Received: by mail-wm0-f68.google.com with SMTP id c17so1445842wmc.3; Wed, 26 Oct 2016 10:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ktHKNthaSayFPIHrvjFlj/T+biTfCFrhsBn0SsJgdek=; b=XTuYeTfwTDblU6aFY4bQbJzaN0ABvUeMH9es/Ccor7c79jv2TLzynQhbTuNjhMMvX6 bjwWFPfgmfb4dKxwgUa7DKbkTqFnB6NAU0eAhJ/x5p1Q0KTANevbd5f3SZWMkspynXtY DHJ1rq8aPmnaU/FzI5H8pKUVeiJmOXfgJ2D00qLKQ1/+CDqH10tA2wFg82w7aIo3XIRH aoXZfVwKhKYQHZskIiEOrGLnFFNwSqCSjI2a4o1m3nVUt8KTGajAtY8szki03xa0zyvm y4K/RvdVFsCLYeDSswfzAl1DDNzgtS2GNMCjO7ZHCBxdZzVtrkK25gTIF9TJDURuf4/0 7ogw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ktHKNthaSayFPIHrvjFlj/T+biTfCFrhsBn0SsJgdek=; b=Y/Jyb4W6zoQCcehGKDh7XU8VSsGGkea3i5h0wmoMe717VJuUpMRZxp/MdCioXLQTkX /kS9HCgGLJqiQxfYAB4MxE7R9Xe8i4qBUc/bnvaMl6bCBUdFII6cuZrAZrm5B7diCJQA x3RbDdqFlqs17krKzmxnZVX/DV2fTKsMwnGQEcgDkSB4HG9ILu3cZHOuQ/PHUAPICFju mztYd0mXP99k+TkF6IqpC8QtRO7dUY6RyltDG7JIBrhPVSeF6fVzj6EvWCpD5pfP7rt7 2sRboqgxz0GOI/6mMHxoPjkAiNFpatsBhWD0tbEKEOm47taNv2Pbw2xLoR8CEixzDu9D Y45Q== X-Gm-Message-State: ABUngvfNkud2EaGb7G+w4vmdZG+3atv/GPTQbFvSzJRTEK+gSkeqp43eyX7EM2leUQAfwQ== X-Received: by 10.28.1.4 with SMTP id 4mr7593014wmb.10.1477501869069; Wed, 26 Oct 2016 10:11:09 -0700 (PDT) Received: from amir-VirtualBox.Home (bzq-79-177-34-153.red.bezeqint.net. [79.177.34.153]) by smtp.gmail.com with ESMTPSA id h3sm3640196wjp.45.2016.10.26.10.11.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 10:11:07 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi Cc: Vivek Goyal , Andreas Gruenbacher , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH] ovl: update S_ISGID when setting posix ACLs Date: Wed, 26 Oct 2016 20:10:40 +0300 Message-Id: <1477501840-25066-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since operations on upper are performed using mounter's credentials, we need to call posix_acl_update_mode() with user credentials on overlay inode to possibly copy-up and clear setgid bit, before setting extended attributes on upper inode. This change fixes xfstest generic/375, which failed to clear the setgid bit in the following test case over overlayfs: touch $testfile chown 100:100 $testfile chmod 2755 $testfile _runas -u 100 -g 101 -- setfacl -m u::rwx,g::rwx,o::rwx $testfile Signed-off-by: Amir Goldstein --- fs/overlayfs/super.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 30263a5..16cc844 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -522,6 +522,22 @@ static unsigned int ovl_split_lowerdirs(char *str) return ctr; } +static int +ovl_set_mode(struct dentry *dentry, umode_t mode) +{ + struct iattr iattr; + int err; + + if (mode == d_inode(dentry)->i_mode) + return 0; + + iattr.ia_valid = ATTR_MODE | ATTR_CTIME; + iattr.ia_mode = mode; + iattr.ia_ctime = current_time(d_inode(dentry)); + + return ovl_setattr(dentry, &iattr); +} + static int __maybe_unused ovl_posix_acl_xattr_get(const struct xattr_handler *handler, struct dentry *dentry, struct inode *inode, @@ -560,6 +576,18 @@ ovl_posix_acl_xattr_set(const struct xattr_handler *handler, if (!inode_owner_or_capable(inode)) goto out_acl_release; + if (handler->flags == ACL_TYPE_ACCESS) { + umode_t mode; + struct posix_acl *newacl = acl; + + err = posix_acl_update_mode(inode, &mode, &newacl); + if (err) + goto out_acl_release; + err = ovl_set_mode(dentry, mode); + if (err) + goto out_acl_release; + } + posix_acl_release(acl); err = ovl_xattr_set(dentry, handler->name, value, size, flags);