From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 073D1FA372B for ; Wed, 16 Oct 2019 21:54:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C807C21925 for ; Wed, 16 Oct 2019 21:54:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262850; bh=hk3ubyqBbIe4/ginOWZCsT8yD+1gPxyx+dt9fX/myL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=k2oUqWjAEPYGCY5yNYQm/843aFdgllgsPIe5vYJbQC6q2oHND9eS4cFol4U92OWMm 8aJxXXST7HnPoPktB9b6hZukhZFFFqdW0EvWkvwrrZfVn4Hc2NrDgjYm6j/E5DGSd3 dzhZPHl6t4a7MrrOd9AObgtT04vSgJSqrxa7cm3k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437691AbfJPVyJ (ORCPT ); Wed, 16 Oct 2019 17:54:09 -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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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