Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2452722imu; Mon, 17 Dec 2018 02:08:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/U9fHHSlcRZ3lDA0fnnov3qPLiESdKh8/VAfr2b5JsMr4z8EmftML1StPO5RWuCjkmVre3Y X-Received: by 2002:a62:4714:: with SMTP id u20mr12178749pfa.144.1545041281511; Mon, 17 Dec 2018 02:08:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545041281; cv=none; d=google.com; s=arc-20160816; b=FdhY/GEBGm0niuaMpyYfEnu/nw0nuRTC0WHZPI6SWf1IhGqvbVPnkfrC44IUzd8mJL UMDVzwtXKwtOw20Evbj62G+hQjxbgdnE1VjvoJwIlK/+KUCglX17fLTLRGhNL6HC/eIm z6zxxP9R0ltYrlnYw0p6MYVDEzjcvTiF46wEY4Ydxh/Hopxeldc9uaxcqwrsNWJe6poU duiEO9quKOem2rD6TobeyhqojnYhUnxtoEXGWlL+CWFA7L0PWm74EXOdmt0ZmO893nq2 q3B24EUBSp7vJHSs5udHWODtOaH4Zn9w+kQP6exHEosLmwVjQ+rzJXANAhyZw7fkt7LQ P38w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=9o5Lg4wlfzRY7X4k9Khj2bgHW1rtl4RVyXLHS4Wdyos=; b=x2+2Q5/RpZqEW2C/OxXWpijAoFp7yGnlVryVJjoL63ZOIk9lkrXbXiZruG7JVyUvE8 JK/f/O9rshOrVLO+vvM+UFqeKX/56RJLvipavxiGojLApUwto0SQQWr8UL1LbWzNx7Zr 95jSJYXEiSfLFUXU40NkEJp8vNKiaL5wygESsdfuc56FnZrXZk9+Sz95wDZrloP0DaTd ZT6i6MMCggMjTlEtlA9yznZ1ZHkwkwUewDuk0Jsi6kbrYMduP8NGQ2FqYf6O9o5FjarD Lgm3b6rBAXRnvmTltXlN6In2VdgEop694n9sI/GkgukXKIniG/3M6WfofFuhjjf04VLC sc6g== 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 t20si10747386plj.94.2018.12.17.02.07.46; Mon, 17 Dec 2018 02:08:01 -0800 (PST) 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 S1731794AbeLQI2E (ORCPT + 99 others); Mon, 17 Dec 2018 03:28:04 -0500 Received: from mx2.suse.de ([195.135.220.15]:55858 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726692AbeLQI2E (ORCPT ); Mon, 17 Dec 2018 03:28:04 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7197EAF03; Mon, 17 Dec 2018 08:28:02 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id E7D341E1475; Mon, 17 Dec 2018 09:28:00 +0100 (CET) Date: Mon, 17 Dec 2018 09:28:00 +0100 From: Jan Kara To: Alexander Lochmann Cc: Jan Kara , Al Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Horst Schirmeier Subject: Re: [PATCH] Abort file_remove_privs() for non-reg. files Message-ID: <20181217082800.GA28270@quack2.suse.cz> References: <4903939e-d3d6-b0c2-9c33-0fea0a61213c@tu-dortmund.de> <20181207175811.GZ2217@ZenIV.linux.org.uk> <5c86e85f-0ad4-935a-3021-7046551f361f@tu-dortmund.de> <20181208004944.GA2217@ZenIV.linux.org.uk> <20181210094722.GB29289@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 14-12-18 11:55:52, Alexander Lochmann wrote: > > file_remove_privs() might be called for non-regular files, e.g. > blkdev inode. There is no reason to do its job on things > like blkdev inodes, pipes, or cdevs. Hence, abort if > file does not refer to a regular inode. > The following stacktrace shows how to get there: > 13: entry_SYSENTER_32:460 > 12: do_fast_syscall_32:410 > 11: _static_cpu_has:146 > 10: do_syscall_32_irqs_on:322 > 09: SyS_pwrite64:636 > 08: SYSC_pwrite64:650 > 07: fdput:38 > 06: vfs_write:560 > 05: __vfs_write:512 > 04: new_sync_write:500 > 03: blkdev_write_iter:1977 > 02: __generic_file_write_iter:2897 > 01: file_remove_privs:1818 > 00: inode_has_no_xattr:3163 > > Found by LockDoc (Alexander Lochmann, Horst Schirmeier and Olaf > Spinczyk) > > Signed-off-by: Alexander Lochmann > Signed-off-by: Horst Schirmeier The patch looks good to me. You can add: Reviewed-by: Jan Kara Honza > --- > fs/inode.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/fs/inode.c b/fs/inode.c > index 35d2108d567c..682088190413 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -1820,8 +1820,13 @@ int file_remove_privs(struct file *file) > int kill; > int error = 0; > > - /* Fast path for nothing security related */ > - if (IS_NOSEC(inode)) > + /* > + * Fast path for nothing security related. > + * As well for non-regular files, e.g. blkdev inodes. > + * For example, blkdev_write_iter() might get here > + * trying to remove privs which it is not allowed to. > + */ > + if (IS_NOSEC(inode) || !S_ISREG(inode->i_mode)) > return 0; > > kill = dentry_needs_remove_privs(dentry); > -- > 2.19.2 > -- Jan Kara SUSE Labs, CR