From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55CE2C43613 for ; Thu, 20 Jun 2019 18:01:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 317ED215EA for ; Thu, 20 Jun 2019 18:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561053714; bh=9zCuTz2MR1VwzSH06hdNX1UrRVjULp8CQKn86vM3loQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Tb6vmCzPi5j396Wf4leMF1nwzvm5+y0xJ2g6AX+qz8YhkVLv0TJMgFjajKtsH15to eHecg1/41I58F7ZciUUfwN2xgPXxbZhrn2eAahhWrc1iTrohcwxCCHBCBuMCP3eO5A Nrn+PHptSZvwHaR1VaxP/QhQD5PziXqtFYGSaqdk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727339AbfFTSBx (ORCPT ); Thu, 20 Jun 2019 14:01:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:51896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727316AbfFTSBw (ORCPT ); Thu, 20 Jun 2019 14:01:52 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1472720B1F; Thu, 20 Jun 2019 18:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561053711; bh=9zCuTz2MR1VwzSH06hdNX1UrRVjULp8CQKn86vM3loQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H1jApYnR2XRDbEmgiPRAqaRz6bMC5S3uDqxDjiLbT29uhCFbgr/lRZmThWC2M6zkJ +q4Y80NzMLtA2r+WsKNJF3ke+HoZF7cRTpJB6tHaNU6sINpK53ccEMXBQ2yncejlM9 3Qv+VSCHiRmvEE9eA9Jrj+30T4jYLWMs7xtvTMBE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Alexander Lochmann , Horst Schirmeier , Al Viro , Zubin Mithra Subject: [PATCH 4.4 84/84] Abort file_remove_privs() for non-reg. files Date: Thu, 20 Jun 2019 19:57:21 +0200 Message-Id: <20190620174349.500021445@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190620174337.538228162@linuxfoundation.org> References: <20190620174337.538228162@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Alexander Lochmann commit f69e749a49353d96af1a293f56b5b56de59c668a upstream. 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. AV: more to the point, for devices there might be any number of inodes refering to given device. Which one to strip the permissions from, even if that made any sense in the first place? All of them will be observed with contents modified, after all. Found by LockDoc (Alexander Lochmann, Horst Schirmeier and Olaf Spinczyk) Reviewed-by: Jan Kara Signed-off-by: Alexander Lochmann Signed-off-by: Horst Schirmeier Signed-off-by: Al Viro Cc: Zubin Mithra Signed-off-by: Greg Kroah-Hartman --- fs/inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/fs/inode.c +++ b/fs/inode.c @@ -1744,8 +1744,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);