Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2907096ybz; Mon, 27 Apr 2020 06:46:32 -0700 (PDT) X-Google-Smtp-Source: APiQypK9HGID2OMEsYCa/eGPrkvwwagp/zfPfPZevVOOHXFc7no/zxsOry0/SRWYch6BNZbmktKi X-Received: by 2002:a50:a883:: with SMTP id k3mr18575195edc.198.1587995192471; Mon, 27 Apr 2020 06:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587995192; cv=none; d=google.com; s=arc-20160816; b=Q42I+/Ed6I/0bO3g3ov6BMRRdphtFYLdI7dpHmHOZBVLI+RDlYpilkdIb8SEGh+0Mn 4e/Ik8+rIsS7z9q3Eld+oJa1yTLWOGtpFgwmAaj8OF0cQxlJLewXFw8qeumlRiNvNj50 LyqnpR1bwo/d27oLgoS/CHm61wHelucTgssbnqAQk1UOqL1C6ZWfV2PeyDeZbye0Ib3r mW//VDqEu4RX1bTkFLLHSFcFhxNifbQ7DbLMhWW9cmPRyynI/syLOrqtNqVNxlxJfiXr JQtM6ukm/PcUKChwF+Ow0j7V+kCya0v9Cv5sXHV3wmFkVNgPZBt1Vks5c8qikqinRbhv 6JTw== 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=ACCa4pOI6as1SXAQohNNaP9SdoMTMJ+lcCy16K/cbSQ=; b=gmbCLnD39HQNY452+GjWi/NIi+GSWNaluekQNG4tOBDb2jSwrNV+FyfSfnSFchyKrG p80+InWobtzEto5f2vxxC9DFeS8z7S1Y4EmPKJ1Vc2OIXR+rGd9ecxbd8hfJtwQA++SD jgUYe1FCOS/ryPy/ivh/slG0ThYyuw7e8lpaT/WVpJC//vkQU0sr8Q1JAWd24oXA0tvV DdKjRClO9UjuMANW4yGwUnAMYM+/fXCHOFJ8z1JmuT847jE5bR0fG89znngTYF7YIsoH 67b2s8MWJBYhPQjGKzp7LZg4zTLkX0+sC8Zl4O6NubfYWXzGvu3ZwWhegzIJQfeqDeKj FINQ== 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 cq7si7603413edb.319.2020.04.27.06.46.09; Mon, 27 Apr 2020 06:46:32 -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; 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 S1728298AbgD0Nmy (ORCPT + 99 others); Mon, 27 Apr 2020 09:42:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:34888 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727010AbgD0Nmx (ORCPT ); Mon, 27 Apr 2020 09:42:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 919B1ADB5; Mon, 27 Apr 2020 13:42:50 +0000 (UTC) Date: Mon, 27 Apr 2020 08:42:47 -0500 From: Goldwyn Rodrigues To: Roberto Sassu Cc: zohar@linux.ibm.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, silviu.vlasceanu@huawei.com, krzysztof.struczynski@huawei.com, stable@vger.kernel.org Subject: Re: [PATCH v2 1/6] ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash() Message-ID: <20200427134247.vcpx6gyh62seucnf@fiona> References: <20200427102900.18887-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200427102900.18887-1-roberto.sassu@huawei.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12:28 27/04, Roberto Sassu wrote: > 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. Thanks for fixing this. Reviewed-by: Goldwyn Rodrigues > > Changelog > > v1: > - fix comment for f_mode change (suggested by Mimi) > - rename modified_flags variable to modified_mode (suggested by Mimi) > > 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 > --- > 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 5201f5ec2ce4..f3a7f4eb1fc1 100644 > --- 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, 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 > @@ -557,13 +557,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; > } > @@ -581,8 +581,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.17.1 > -- Goldwyn