Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2088457ybp; Thu, 10 Oct 2019 02:00:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwl9ToW7sZt/ooGL2XbRvPwvZIcUCCDwhIlcmmowrEu4TFwxQ608Nelj3czhjXSLjqgo87B X-Received: by 2002:a17:906:1d02:: with SMTP id n2mr6973576ejh.303.1570698009265; Thu, 10 Oct 2019 02:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570698009; cv=none; d=google.com; s=arc-20160816; b=EPGCLINJr0vGl/UgBwMK1JvVbhJ4UaSbSMEcyj92xfzG27tHrxbJ/mpNyE4P5u1WvU xkKCwEaREFd1xRWv5L7w25U6wtnf21ZwphDXewHtg9zugqlc3ELeBhKmdGBndOv2tccO i0uJRSYyLxOetYm62yf6V4PDiajbgY4BJCYtbUKwk5wJ/gZ4w5wZBNH895UrSo7IsqyO Hwj760FUe7lxsxoPZOSOj1qEQ4mtzGMxjYXrYiAjq6A0FxUAipI1ZsFnwvSfaO9552l9 zemHA5aN8L7xSJOnlT3JP1wWG10O4/nqeTgyfCpf5iprCJU1HrZ4Zl0i0iqStzNgNBgD pyvw== 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=oXvsen9VDoantt2EIzIPBf0VGahhZ9cSG7zDG6cGXQE=; b=i5Gs72NEYAyWWzCdPjo4vZgw0jJqajyXcj/kdak+7Mo66ljOa7oHuoZcMNXt40HARl e4Fkuf1V5JdgeQyiCg15kKszkEDpWlwx0+0HNyF0D+UWO0yK2da3sDPq0Giz94B5+sf3 hKro+OtLgmaqgszmxS2GJVFXCbM+O4sw6g80GqXCZWLNe7ZlLwkaCT/SScKOj/3nKI84 UOna94ZvF51+wglxkhxkzcPgzWXBxVwh6z6zeLKQeTOTyS5Hjw9LyLz4xaMPLZnV/DoX m7AuVCFR9vgjgObp7OfadLQzOOoO5GPMKgPGnD3pW4SK51gRocc54eZkD0RnePc4fwB5 rvJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IZf5zC9F; 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 j12si2711333ejx.282.2019.10.10.01.59.46; Thu, 10 Oct 2019 02:00:09 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=IZf5zC9F; 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 S2387623AbfJJIq1 (ORCPT + 99 others); Thu, 10 Oct 2019 04:46:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:52176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387615AbfJJIqY (ORCPT ); Thu, 10 Oct 2019 04:46:24 -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 BE8C0208C3; Thu, 10 Oct 2019 08:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697182; bh=yKGquLgQJM6xHAVIyQdIcYLEBg8ctH6tGylCXrJKmP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZf5zC9FDHKXh7Y8Abm69b9HFtdapmsduzf3waDT5Bz7Yw+1tR2f6ZMWsFxdseY5Z PfM4H7LcK96BRpaRfgIoAEPIF96/iXx4QYrQwgH8K/lyLXnNXn6kOadTD35oV87Ckp vSS7Xn49bdLzYV47RJJZ7AWdyzLw1c66wiGTJM/Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sascha Hauer , Mimi Zohar , Sasha Levin Subject: [PATCH 4.19 049/114] ima: always return negative code for error Date: Thu, 10 Oct 2019 10:35:56 +0200 Message-Id: <20191010083608.030280521@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083544.711104709@linuxfoundation.org> References: <20191010083544.711104709@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: Sascha Hauer [ Upstream commit f5e1040196dbfe14c77ce3dfe3b7b08d2d961e88 ] integrity_kernel_read() returns the number of bytes read. If this is a short read then this positive value is returned from ima_calc_file_hash_atfm(). Currently this is only indirectly called from ima_calc_file_hash() and this function only tests for the return value being zero or nonzero and also doesn't forward the return value. Nevertheless there's no point in returning a positive value as an error, so translate a short read into -EINVAL. Signed-off-by: Sascha Hauer Signed-off-by: Mimi Zohar Signed-off-by: Sasha Levin --- security/integrity/ima/ima_crypto.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index d9e7728027c6c..b7822d2b79736 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -271,8 +271,11 @@ static int ima_calc_file_hash_atfm(struct file *file, rbuf_len = min_t(loff_t, i_size - offset, rbuf_size[active]); rc = integrity_kernel_read(file, offset, rbuf[active], rbuf_len); - if (rc != rbuf_len) + if (rc != rbuf_len) { + if (rc >= 0) + rc = -EINVAL; goto out3; + } if (rbuf[1] && offset) { /* Using two buffers, and it is not the first -- 2.20.1