Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2042813imm; Mon, 16 Jul 2018 00:45:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc5z2sqlEeEMnM63ZnSsJfCBCBEaOgP+sL3+V8AJCQKRSvM1h0AGqssYgKtUl1BSviXewCb X-Received: by 2002:a63:c20:: with SMTP id b32-v6mr14142564pgl.400.1531727118491; Mon, 16 Jul 2018 00:45:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727118; cv=none; d=google.com; s=arc-20160816; b=rJD/QrvXJZNivWR4AK+78wvcdNZ0zUE6I275oe5LGes2Qcxvmp79qpHlgJ0wiQHTZ5 8oXnbcYq0nzz3RDinoGPQOJLf1lUlTiL9FnNhYdZzf38wx48HEr5Lkp67stVmyClReV8 etJoCirKaxRz+flQjAcr3ts7J5UHgNIM1DSUezpFHbptSGuPnDJZwNOxdeSu4AVoTHMa 0Q7jhkBTHWffshzH5WOus1YO7oFb0nWm54D+/GTunUjeqUqTLKKQ5zi3SW2uWhkR0Yyi O0fCT5g2cn/F73qEoz7UJa25S7+WN24hHnmcXzcFT+GzKJ8ZA7WCyfjw1szteMbY5ge6 Gilg== 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=weRg0LbOCkZqivvyvwRN6zBul3xYVWAuaO0SQdY1vrE=; b=HAMkP8wse4UI+hXH2mJ5hH7HFhs9gOxklsqu7uDBzFhT6E7P/pbhsPfszcifa9DTEg 1NJEurWDr5phwB1j87cdAwPjF9jAtqyHhyAZKfxfMUpmQr1kF07lUmaUQUeSFT+JJrc2 1rnRfbDGD8IP7JnqdFAA8IjDoZFAmNIrgHRaipK/Vwt/HSDJu6CDArrrNDJynJT0eME1 Wtkaq+pci17JnjyU0EnRd0LUNuwmIDhmtY3u3vzfGLprguTx39DHIwtFKpshMJ8j3cR+ 3QPJlZ7f54DAmBgrLjKZ2xwbW50RzB8qx/u3w7n8p/FYiraBlK1FOhgkoNoRpciFXwdr qEqw== 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 m4-v6si7545647pll.461.2018.07.16.00.45.03; Mon, 16 Jul 2018 00:45:18 -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 S2389167AbeGPIJv (ORCPT + 99 others); Mon, 16 Jul 2018 04:09:51 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48058 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388375AbeGPIJv (ORCPT ); Mon, 16 Jul 2018 04:09:51 -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 68EF8CA0; Mon, 16 Jul 2018 07:43:48 +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.9 19/32] Fix up non-directory creation in SGID directories Date: Mon, 16 Jul 2018 09:36:27 +0200 Message-Id: <20180716073506.937642880@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073504.433996952@linuxfoundation.org> References: <20180716073504.433996952@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.9-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 @@ -2003,8 +2003,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;