Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1045424ybp; Thu, 17 Oct 2019 07:17:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqykZhgBhrQxYLHrG6y+E281tS6PbFGxlahE16dlYDDbWsGnNr49UgayAM7HjFegT5aIsfok X-Received: by 2002:aa7:d04b:: with SMTP id n11mr4112708edo.104.1571321872751; Thu, 17 Oct 2019 07:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571321872; cv=none; d=google.com; s=arc-20160816; b=dCSsgtheIdXaubarEJ+Bzui66VvDkmjpXD9hLAVGvEjii/HUhThubU6FGyiW57BldQ KRuhcGRKJrZVlG83fVplJ8aBPHES7EJai2DK6KzJc7LYkt6EBXJgE90+yZsIySyG9ayv mL5necnVm9B2dbsan8CJ6yOilK9tzbEoJq7H/34Bt8mDG8d9bi+7q0it1nAjSyPxTglv 6BdLvAtm+gPNLTQvPkmCUMLXlFPtdUKnMwDfg7l4UhpHzpJCq30EbyqNK74pgoCXM/JI 17vKUV07wtMT1ejrQex90OriGFqgX/exGXorSWDqIi8ltkCTg5nYlnEFFhyQPrTZ8+jo VZ/A== 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=4gkL6Ttvq2MTAxVXlKXMtZgBVPJorwZ2XJd6BBHeoN8=; b=yceweLnNpX2oC7VynKAkjCYbQtB7KTKuLrA1zZ85CkkLb9KK6RaEqbn2veN2mbK4YQ MYHzZXM5fxATL7gAhXGFgF1Vqv0C6lQ8RapAQGim6HydFQz0DUdsGG/kWxI3lN0x4a8+ Gd6nCuJQjnPgt48zoaarWoDVVGAz93hf7J7R8+DuB9BDoU0sfwGS4jKWDRrRihLFNysW f71VJGOfoy1HET4Z6e53BVjOYXQdN3GN8xYSEiA/DqJQcKqhDcz77H0AW201WIY9SDjY rGybxz40Xpg6Rt69UYz5PKySoLEqR6d6DTOuHEHxzIjse5UxEsdQPKTADyrAwBJXfe6Q ryig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Q/yZWOJy"; 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 z19si1448065ejr.244.2019.10.17.07.17.28; Thu, 17 Oct 2019 07:17:52 -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="Q/yZWOJy"; 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 S2394968AbfJPVyU (ORCPT + 99 others); Wed, 16 Oct 2019 17:54:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:43770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437689AbfJPVyJ (ORCPT ); Wed, 16 Oct 2019 17:54:09 -0400 Received: from localhost (unknown [192.55.54.58]) (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 C9C5E21A4C; Wed, 16 Oct 2019 21:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262849; bh=hk3ubyqBbIe4/ginOWZCsT8yD+1gPxyx+dt9fX/myL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q/yZWOJyh5JwYOz6z+eALNEZGpj1+Ta64fFfeBLJH8sGTqyKQTBFUlFZjKnODTUla FUuv1N2Q29d7whcy8P9IyNt4YsWLdw/hz8Sxb85jeIYH8/sfBq821f4SgSgB/Kh4WS QSGsgLGXjhC/B050jWV9gLHpiE0yKhFMSO3H6PQ0= 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.9 15/92] ima: always return negative code for error Date: Wed, 16 Oct 2019 14:49:48 -0700 Message-Id: <20191016214812.287875830@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214759.600329427@linuxfoundation.org> References: <20191016214759.600329427@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 20e66291ca99a..5155c343406e0 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -298,8 +298,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