Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9103223pxu; Mon, 28 Dec 2020 06:43:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzdsM5QDnuVIQVn+nzSL0GnhVEyNK5tpClSgKISkl85mpNKWGOglQyuAd51JVI3N3gLC4f8 X-Received: by 2002:a17:906:7f0b:: with SMTP id d11mr42191428ejr.7.1609166587714; Mon, 28 Dec 2020 06:43:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166587; cv=none; d=google.com; s=arc-20160816; b=zgNUxyOXndhyeBADOVcJb6hw4Re+4TpgxN5QAnlBlA0h9ibr5ypXrRSA27ujGE61+4 TxzZYD+funkChtvsVyohECgU/RoD8lQs3Z5rHADAccEj9a9exhexbnOQXRo9nKbLz/mE QT2AoGFSZfiWZ41VhF5g4/XjNA2m7pOVRlgJBI8YXxDtgSayaQxLCU7pNrH+sFDxDOcm FyKjmNbE6fqUEcaRSxEd0JmFCaZsIpee8aIDTT9mTlS09/Rhsy/xgEQ8NS2dhOUpYNs2 NCI4UHc1rNXFihDCqAgJb39dANjdEVr7EcWcOfdbxCYaqrAjXgX2LTmb2vJOFhpGsXDs 5PGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mXfC0KkGCmIoM5d7Z6ObBalF1iaKquXw5TYJKGwIgv8=; b=EpzJ0yx1x8imh+SAKzza2zGQqDIbm1gBJ4keyrqBq89PnmnnbcWFKWcUiYZZAWbu7M HHQRKptnXWjAXVp7c5oIS/tQfN+4gbsBluzizjbTl8/BVbADPcL1goLcYchfWKKbkjDc 3k1UMMJO5h5MN6zg5Tf3gq1BoOGa5I1BChr9nA2LsmT3jYizdN9PlDteBcVukQTh1dqi GKCOqxLSjPE/RtXrHsVr+3bVB81hmJUwc7IaYiH/0hGcM497Dp9gTeKl/Vrgtd8Z75Xq qaETeBlGjliPvY83TUQVNrYDkCW/3DSSDIWXkTaAX+fyK7B9d4tdtQfhPSWdSRxKUiqW xlQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zZxnIxI7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si18000486eja.318.2020.12.28.06.42.44; Mon, 28 Dec 2020 06:43:07 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zZxnIxI7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502592AbgL1O2v (ORCPT + 99 others); Mon, 28 Dec 2020 09:28:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:36662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502519AbgL1O2p (ORCPT ); Mon, 28 Dec 2020 09:28:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7EC31208B6; Mon, 28 Dec 2020 14:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165685; bh=wAAhsgCdQH/YGceVJMG3dh+I4tdKvBIPXAipij5iSCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zZxnIxI7jf/75J7MAWxAxHU8K8q2/FLGyHGLJnxQV2maOrrqklFDglQ+uBsRFM8XI /iLRDcAA2sc7wEceebNzaf6UoETfmcw/aAWVIHbNLnhwGjpJmSQXKI94WLT34VebAO Hhu5O1wvZbfPkPoSxso0xaDilE8R5j+RphhvKEk0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roberto Sassu , Christoph Hellwig , Mimi Zohar Subject: [PATCH 5.10 619/717] ima: Dont modify file descriptor mode on the fly Date: Mon, 28 Dec 2020 13:50:17 +0100 Message-Id: <20201228125050.581685971@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roberto Sassu commit 207cdd565dfc95a0a5185263a567817b7ebf5467 upstream. Commit a408e4a86b36b ("ima: open a new file instance if no read permissions") already introduced a second open to measure a file when the original file descriptor does not allow it. However, it didn't remove the existing method of changing the mode of the original file descriptor, which is still necessary if the current process does not have enough privileges to open a new one. Changing the mode isn't really an option, as the filesystem might need to do preliminary steps to make the read possible. Thus, this patch removes the code and keeps the second open as the only option to measure a file when it is unreadable with the original file descriptor. Cc: # 4.20.x: 0014cc04e8ec0 ima: Set file->f_mode Fixes: 2fe5d6def1672 ("ima: integrity appraisal extension") Signed-off-by: Roberto Sassu Reviewed-by: Christoph Hellwig Signed-off-by: Mimi Zohar Signed-off-by: Greg Kroah-Hartman --- security/integrity/ima/ima_crypto.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -537,7 +537,7 @@ int ima_calc_file_hash(struct file *file loff_t i_size; int rc; struct file *f = file; - bool new_file_instance = false, modified_mode = false; + bool new_file_instance = false; /* * For consistency, fail file's opened with the O_DIRECT flag on @@ -555,18 +555,10 @@ int ima_calc_file_hash(struct file *file O_TRUNC | O_CREAT | O_NOCTTY | O_EXCL); flags |= O_RDONLY; f = dentry_open(&file->f_path, flags, file->f_cred); - if (IS_ERR(f)) { - /* - * Cannot open the file again, lets modify f_mode - * of original and continue - */ - pr_info_ratelimited("Unable to reopen file for reading.\n"); - f = file; - f->f_mode |= FMODE_READ; - modified_mode = true; - } else { - new_file_instance = true; - } + if (IS_ERR(f)) + return PTR_ERR(f); + + new_file_instance = true; } i_size = i_size_read(file_inode(f)); @@ -581,8 +573,6 @@ int ima_calc_file_hash(struct file *file out: if (new_file_instance) fput(f); - else if (modified_mode) - f->f_mode &= ~FMODE_READ; return rc; }