Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3710452pxb; Mon, 1 Mar 2021 18:10:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyE5UES1OHb/7FaGj8vEWTeFrpSNNL6VlmZcZqtjcXWGK50oOOEHNILsY7nKiChz0HIINCw X-Received: by 2002:a17:907:778d:: with SMTP id ky13mr17746783ejc.291.1614651042410; Mon, 01 Mar 2021 18:10:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614651042; cv=none; d=google.com; s=arc-20160816; b=e9NRE+iHk/BBqmIcY2CummB2WPWzS4/0l+aLccS7c4fxFMba0Atr/AGaU3n/2g/aTp iUBNja5izP+uMCA/nACArQy1wFoQVOk6V/e7uvRLqWedk7HOJqGz9PKOLQ7RCnt6lmGm iIShu6xrE+DbdgGKdn9BhTa/k+WquM2+G3PR/S1kBAw5ZtNPKtDlNPUjc46S21oKtYnw Enq05+nlNZcDB3Y85cWxqhlXkWsiSqZSQYt0BMr8y5upY66N7AO8GGSNaI8SFdJYzQrN 8FQQnLYnEwByuuYplFoTIS5lCJYbm8xR8sKzsZRUgusGMkZgwlwHL41fyw04m4CtBrsh HSGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mQSzSqoVinlsROazSBr4zsJ/1/3rplIxAwakSMgwAm4=; b=0qONtHjinaVDAO2l015Ut8ebTgYHnY01OstNew64urmhPMo1ouF0dilM0Z346wwPei p/0LpDggzbL1rKIWlH8TcFIHYnz4xDyXgmHhtr1Lp3Y0SX43FIRWA8VErmCOgmlpRUNc 17dlgIphwUXj9el1fgAhYkPmNhKb8qOgB1poOkzsiAdCJb+gj+DjHPAzTQ4KiBp2RN5h p9BHfrMp8F0uylg65iKcZ+hBBq7CIoVRiVsH56kKAyuZ12zWGolaCkibphLqPjM0Ds/L mspUdZCyhE04cbwr7YMIxYzCTl4rlFg7/yE9XLOUAiGEcdV7Lm0Xh4vfGCsxO0ZAYWFc TP9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h16si11897322eje.578.2021.03.01.18.10.20; Mon, 01 Mar 2021 18:10:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239739AbhCBABB (ORCPT + 99 others); Mon, 1 Mar 2021 19:01:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:50960 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239623AbhCASUH (ORCPT ); Mon, 1 Mar 2021 13:20:07 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BC6DAAFAF; Mon, 1 Mar 2021 18:19:21 +0000 (UTC) Received: from localhost (brahms [local]) by brahms (OpenSMTPD) with ESMTPA id 1f142bb4; Mon, 1 Mar 2021 18:20:31 +0000 (UTC) Date: Mon, 1 Mar 2021 18:20:30 +0000 From: Luis Henriques To: Vivek Goyal Cc: Miklos Szeredi , linux-fsdevel@vger.kernel.org, virtio-fs@redhat.com, linux-kernel@vger.kernel.org, "Dr. David Alan Gilbert" Subject: Re: [RFC PATCH] fuse: Clear SGID bit when setting mode in setacl Message-ID: References: <20210226183357.28467-1-lhenriques@suse.de> <20210301163324.GC186178@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210301163324.GC186178@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 01, 2021 at 11:33:24AM -0500, Vivek Goyal wrote: > On Fri, Feb 26, 2021 at 06:33:57PM +0000, Luis Henriques wrote: > > Setting file permissions with POSIX ACLs (setxattr) isn't clearing the > > setgid bit. This seems to be CVE-2016-7097, detected by running fstest > > generic/375 in virtiofs. Unfortunately, when the fix for this CVE landed > > in the kernel with commit 073931017b49 ("posix_acl: Clear SGID bit when > > setting file permissions"), FUSE didn't had ACLs support yet. > > Hi Luis, > > Interesting. I did not know that "chmod" can lead to clearing of SGID > as well. Recently we implemented FUSE_HANDLE_KILLPRIV_V2 flag which > means that file server is responsible for clearing of SUID/SGID/caps > as per following rules. > > - caps are always cleared on chown/write/truncate > - suid is always cleared on chown, while for truncate/write it is cleared > only if caller does not have CAP_FSETID. > - sgid is always cleared on chown, while for truncate/write it is cleared > only if caller does not have CAP_FSETID as well as file has group execute > permission. > > And we don't have anything about "chmod" in this list. Well, I will test > this and come back to this little later. > > I see following comment in fuse_set_acl(). > > /* > * Fuse userspace is responsible for updating access > * permissions in the inode, if needed. fuse_setxattr > * invalidates the inode attributes, which will force > * them to be refreshed the next time they are used, > * and it also updates i_ctime. > */ > > So looks like that original code has been written with intent that > file server is responsible for updating inode permissions. I am > assuming this will include clearing of S_ISGID if needed. > > But question is, does file server has enough information to be able > to handle proper clearing of S_ISGID info. IIUC, file server will need > two pieces of information atleast. > > - gid of the caller. > - Whether caller has CAP_FSETID or not. > > I think we have first piece of information but not the second one. May > be we need to send this in fuse_setxattr_in->flags. And file server > can drop CAP_FSETID while doing setxattr(). > > What about "gid" info. We don't change to caller's uid/gid while doing > setxattr(). So host might not clear S_ISGID or clear it when it should > not. I am wondering that can we switch to caller's uid/gid in setxattr(), > atleast while setting acls. Thank for looking into this. To be honest, initially I thought that the fix should be done in the server too, but when I looked into the code I couldn't find an easy way to get that done (without modifying the data being passed from the kernel in setxattr). So, what I've done was to look at what other filesystems were doing in the ACL code, and that's where I found out about this CVE. The CVE fix for the other filesystems looked easy enough to be included in FUSE too. Cheers, -- Lu?s