Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2038804imm; Mon, 16 Jul 2018 00:39:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeR/JqsWhU94mlqp2k4JKcQ3EI+1Ne4DYP+OciKHl7HruisjFgIMlTQJmq4deXXpaVfpPJm X-Received: by 2002:a17:902:6105:: with SMTP id t5-v6mr15711362plj.92.1531726769406; Mon, 16 Jul 2018 00:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531726769; cv=none; d=google.com; s=arc-20160816; b=l4nlMC7OutN0Ey8wk7JOjy/5MlT3qn5FMZ+FR4UdhZH4YymEslbFZlDo4XCVpQ+F7Z BxQg+yN0IHUAYnk3JHL3iw7F5baEtVdjgckTD/CVHSQq/yiKMA75DiWwxIDeiNsjdDTo bjB5gdlDZEavoTe9ZVXyn8ztXFhtc7iHbUscZIaWueHh22mw6kDUDBvCfR2bRXOB2W60 HQO/p6/REK/5LkPeYJKkXbT2Cg729hC02uDmmszAmYq+j0t6TgMpt2aLU7pTmBCz4iTI uOjoDCu1E3dnm5J6lxvQRNQDaRElQdjf/PeuohgESar7yCy5zR5pubca9TeyXjxgEMKH oJBQ== 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=/AYTWYuPqGbV1IeGKbPk99OtJ5k44VKls3BD/DMLja0=; b=GKVFxQ8aTaOff81vVxjAZrUJjpD2K4gua2J+bvqgASBVos8YFUePbbS5ePEi0qPkAq WaWfGqqYj227Oo1JKyy4FYK72/W1evs/sQmflJtuHjYCVR+5FQj5JMpgrxfzlNaaAAe8 pooYEZiy6GWQ/DDm5KPZi5AWsctIFFeOIOOpbyLNGRZjXq75OrIf8aMX0iPpX4f7myLJ UDFkcA6YlB8KJcHxWtaiP8zAo+HLua/U4N5qLvq3XpyFAitZSAYMSBPZMzzPq3GaegY+ 14v2qszALAgMOFrLrBnaZ2YVbDrCqW7TRmDE6UmuYyRIP5HjyldAXNzfuoN8jHHoO4Dk LnQg== 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 m12-v6si2661353pgk.305.2018.07.16.00.39.14; Mon, 16 Jul 2018 00:39:29 -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 S1732158AbeGPIEU (ORCPT + 99 others); Mon, 16 Jul 2018 04:04:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46882 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729883AbeGPIES (ORCPT ); Mon, 16 Jul 2018 04:04:18 -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 80366CA0; Mon, 16 Jul 2018 07:38:17 +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.17 31/67] Fix up non-directory creation in SGID directories Date: Mon, 16 Jul 2018 09:35:00 +0200 Message-Id: <20180716073448.068935535@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073443.294323458@linuxfoundation.org> References: <20180716073443.294323458@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.17-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 @@ -2013,8 +2013,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;