Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2043048imm; Mon, 16 Jul 2018 00:45:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe5J3gUUs5dJjaMfpfa27h9l0omQV3ZcKzQwvWWO8cmmvchTSQpBps2+HMnvZ1II3aUAxkA X-Received: by 2002:a63:144b:: with SMTP id 11-v6mr14902880pgu.219.1531727136991; Mon, 16 Jul 2018 00:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727136; cv=none; d=google.com; s=arc-20160816; b=t9aF4TWZrRciuwASVCrf8Tis8PFHi1GVDXqOlr9MC15/nT8qvvU7CEt3KFHW+jfMFh eGVVeg//sWRrtDmngmkllDc5qrkmwo8r8ygyKuwWv36ocB1Kgud6WvkkWfqsmB9wEPrM t13Xj7zuM40RZP2Csmf+1MvlWc/d2QyvWnm2LA574Po3dCDu07NAtz0BjBgczVpM7DKL 5u8RvrXJmLF2Ug+dECL3aVcct6ReJU87H032DpliuD+Vznp0xuJWOnsKf4LgPY85F/sG ZERDjYOa2Y9unDtKdb+XGB7U+zCXOC4sek8XrmfGEd8CFdDZp2TaRUtpDUKJHpc4WvZx wNNQ== 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 :arc-authentication-results; bh=hFhHPNKrjwhKgxIsje0S3JR39kjwHRl9c2bVwcmbqTE=; b=uBXmf0AWYWjPlKkWby9IJPZeB/+aGePvgjT8X9cG8ESs2A43Vs1t0QjAIRzseHuU6+ f8DKTVWHjFLZwNAY20YzQtM9Uop3uMrBmWP6ygiL6UHnoG/XTyHhsCn7sH4/uuIsYtnY fO38hCVy5LYKpiXYgC6jOJg/frBhL/SU76wUiOt8ZXsx3qjA8h6RvP9GTrIyk67dg7yL EObTOY5gRA6YHh0eMTN38h7Np3mJ/up7151CChiDOh/6vpdh2xBMYIrLXpGKbZBkT1kX 3Qzx5IB7hjem6j9YCIAkijeohSvSZvRuzGkx3ZPJTMopstbqd2leot3oeeswxu1V/dgF TnDw== 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 w185-v6si28514403pgd.133.2018.07.16.00.45.21; Mon, 16 Jul 2018 00:45:36 -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 S2389259AbeGPIKL (ORCPT + 99 others); Mon, 16 Jul 2018 04:10:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48122 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388375AbeGPIKL (ORCPT ); Mon, 16 Jul 2018 04:10:11 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A9B23CA1; Mon, 16 Jul 2018 07:44:07 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Andy Lutomirski , Al Viro , Linus Torvalds Subject: [PATCH 4.4 13/43] Fix up non-directory creation in SGID directories Date: Mon, 16 Jul 2018 09:36:18 +0200 Message-Id: <20180716073513.229883114@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073511.796555857@linuxfoundation.org> References: <20180716073511.796555857@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: Linus Torvalds commit 0fa3ecd87848c9c93c2c828ef4c3a8ca36ce46c7 upstream. sgid directories have special semantics, making newly created files in the directory belong to the group of the directory, and newly created subdirectories will also become sgid. This is historically used for group-shared directories. But group directories writable by non-group members should not imply that such non-group members can magically join the group, so make sure to clear the sgid bit on non-directories for non-members (but remember that sgid without group execute means "mandatory locking", just to confuse things even more). Reported-by: Jann Horn Cc: Andy Lutomirski Cc: Al Viro Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/inode.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/inode.c +++ b/fs/inode.c @@ -1937,8 +1937,14 @@ void inode_init_owner(struct inode *inod inode->i_uid = current_fsuid(); if (dir && dir->i_mode & S_ISGID) { inode->i_gid = dir->i_gid; + + /* Directories are special, and always inherit S_ISGID */ if (S_ISDIR(mode)) mode |= S_ISGID; + else if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP) && + !in_group_p(inode->i_gid) && + !capable_wrt_inode_uidgid(dir, CAP_FSETID)) + mode &= ~S_ISGID; } else inode->i_gid = current_fsgid(); inode->i_mode = mode;