Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp125427ybm; Tue, 26 May 2020 12:24:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLiJDsumwrwCVpuRbIeQYkQm3kgV8/EW/721iQt/QKSKQtFuIC27SDRD5RxsgYlETtiG8H X-Received: by 2002:a05:6402:c2:: with SMTP id i2mr21690296edu.224.1590521070115; Tue, 26 May 2020 12:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590521070; cv=none; d=google.com; s=arc-20160816; b=mTu4IheX9DQpi3l5MJXlckZH/g+Ia+w2Gqi00YVZINaXLnLGcAl7YIg+G4h/wjQyRC krgC/kY9DXYZo291oSHZQeuwOmhA1r2f/K8sBn/FCUChj89+SPu2E0SEXBmGQ1jfqHQN 1qFH0+6QpvdnaemeXG+Qf9u1WnyLEpJrpBO7xN3cRG4xa6eDsk+MiaGFYLKWtyEN4Awt atf31lbEAJCZTLQm7phb6JOUqIG3R8eh/yI1OHEFQSxctdcHOWsECtSg+z6aYabz4cXX c/RnIZt3nc9dBSz8Xbn36hZ8acJcAoCDbl4w0FNj32/Bv2OWhj4Xx7StljEfA0m8wjkP VR1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FoMcVLBeQAXpgNNrM2ZINYhXxCY2JZboRxn1kymEE3M=; b=sOiZdf+4BHRu8K7oCnh4tTD+gd5Q2agwNEZ3OCL3tOu6eDZAzOj9no8ad17+GOb75R QaHxcu7Cz5/RalJPW9LpdeBOG06YEmU9Zz2Bg7o8xbHEgBrxsq9AfJXfuGB8/PLITaVh RrDxicc7yufeE+ELg5mFZq+cUeoJ40KrgK+iCYlUhsoEtUT+2xLKhhMyiTtToxQNWisd q7PYUkm6oAI9Tu5inzw8uV+etVAfyRgKFw69nf5pp25ecMOfAipAMPUCN9ndK/RT6mil reesVr9UZqJprAzPzyhmMj7VkfQFh038GEIJS0VVEUmMxKBbZvJGtmdPYCJo6dNQb+mo /rxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r1OVpryC; 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 w23si482210eju.658.2020.05.26.12.24.06; Tue, 26 May 2020 12:24:30 -0700 (PDT) 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=@kernel.org header.s=default header.b=r1OVpryC; 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 S2404103AbgEZTVa (ORCPT + 99 others); Tue, 26 May 2020 15:21:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:41018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390092AbgEZTLg (ORCPT ); Tue, 26 May 2020 15:11:36 -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 63FEE208A7; Tue, 26 May 2020 19:11:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590520295; bh=PEqJ5eyUtSxJhYnhnCrIAr5eo6UL8Kd/34b2Bw2Fusg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r1OVpryCH45zhYJVL2bMGKrfVaS7xyF4RamV3TU7C41GjICqt703cSGv4oy/v95eE F0dOZKz5+DNk2R8NP2nvyKlqGX/nBUwJBPCCXCEZOS29z6K6CVJ/b2V0GykamTExeW CtV2jx2qmobuE70diEZ7cD35zwrtPX4KrIokTE9o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roberto Sassu , Goldwyn Rodrigues , Mimi Zohar , Sasha Levin Subject: [PATCH 5.6 003/126] ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash() Date: Tue, 26 May 2020 20:52:20 +0200 Message-Id: <20200526183937.776295899@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526183937.471379031@linuxfoundation.org> References: <20200526183937.471379031@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roberto Sassu [ Upstream commit 0014cc04e8ec077dc482f00c87dfd949cfe2b98f ] Commit a408e4a86b36 ("ima: open a new file instance if no read permissions") tries to create a new file descriptor to calculate a file digest if the file has not been opened with O_RDONLY flag. However, if a new file descriptor cannot be obtained, it sets the FMODE_READ flag to file->f_flags instead of file->f_mode. This patch fixes this issue by replacing f_flags with f_mode as it was before that commit. Cc: stable@vger.kernel.org # 4.20.x Fixes: a408e4a86b36 ("ima: open a new file instance if no read permissions") Signed-off-by: Roberto Sassu Reviewed-by: Goldwyn Rodrigues Signed-off-by: Mimi Zohar Signed-off-by: Sasha Levin --- security/integrity/ima/ima_crypto.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 7967a6904851..e8fa23cd4a6c 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -413,7 +413,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) loff_t i_size; int rc; struct file *f = file; - bool new_file_instance = false, modified_flags = false; + bool new_file_instance = false, modified_mode = false; /* * For consistency, fail file's opened with the O_DIRECT flag on @@ -433,13 +433,13 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) f = dentry_open(&file->f_path, flags, file->f_cred); if (IS_ERR(f)) { /* - * Cannot open the file again, lets modify f_flags + * 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_flags |= FMODE_READ; - modified_flags = true; + f->f_mode |= FMODE_READ; + modified_mode = true; } else { new_file_instance = true; } @@ -457,8 +457,8 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) out: if (new_file_instance) fput(f); - else if (modified_flags) - f->f_flags &= ~FMODE_READ; + else if (modified_mode) + f->f_mode &= ~FMODE_READ; return rc; } -- 2.25.1