Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2074375ybp; Thu, 10 Oct 2019 01:43:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4z2TKPwutBvhkozZy+hIAjdsTA6XvnwqArfzSUC37SvXNjR3K0sJu2/IddgrYW91EUEwb X-Received: by 2002:a17:906:314c:: with SMTP id e12mr6840526eje.140.1570697001030; Thu, 10 Oct 2019 01:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697001; cv=none; d=google.com; s=arc-20160816; b=UafO66m/x1drenS9VHzwRr35dvwDsqyK4DpHNRbu0XeVTRtgGSDeXDlupnVZBVHWcu VfFRSljgH8cZgJRuAeCjFfjqBYU0H9a9oLbtaEQyjclEedPaa2+4kLr6I44a44eoSbX2 uwFwqiILXBM4zFayGqYaFxNincTnRT3QLRzNODd/3blE7S7yqmtujXoSPUNgBxqKCALA EzHYfBb2xU0l7jZ5xzCUXS6pUih/Q4iMS0eUF6uCI/Uo2JoLW35VSrrIUdLD1sqPxiib 2+NfGzBTWuLXsrWdDGGMl/a0UdXwag9yW6WEx6yWOD/DeoH1hEzz2TGg9Bba9Eqx4GkL v+SQ== 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=dXiP7B6kHy5G+wut7QbUJraRD8YKbCrWPjihfWR5pfU=; b=cmjmy2GTPWtZtKxdLIUsnWoMIYw7fGup+ItnKHrMa6YKIGSV7Io+jgIPO/NN6g2mej Ej5bPTryT7oA+IzvMrcJRvLWD8YTdPOGkzSKsHSFBfyg2qO9Fo8DsK8+pHwDB/EOM7Kp 8Fid0SbFGNRM7t4SR3Ub+Lfa/I8JqYhcuYiu4XedBPy+DLYOfP+iL/ekOzD1DOrux8y3 xhkqBLkQIyTqCnI4uNWVe0/VrMGFWcTHRmmZJMsyHMT+wAVHtVopV2W2ST9KdFLSVHuZ LCg2eeU1aeR557jEqZ7q/12yesg6MIrHUAFyBEZ6Hv8QaAHvXgCFe9TZwg78ghTCsP69 m7mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2WRu0AWd; 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 b14si2681317eju.187.2019.10.10.01.42.57; Thu, 10 Oct 2019 01:43:21 -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=2WRu0AWd; 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 S2388337AbfJJIl0 (ORCPT + 99 others); Thu, 10 Oct 2019 04:41:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:45802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388326AbfJJIlZ (ORCPT ); Thu, 10 Oct 2019 04:41:25 -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 349372054F; Thu, 10 Oct 2019 08:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696884; bh=6vs+mxOj8LdnxQhig/ZrlnZJRypReXhz9Lk/p8RpLM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2WRu0AWdb6GqRdpEgs62x7KcfLoHw8nT/Ei3c+/XNtecRuIt9a/LZZBiHw4+Qn4pu rdxipnIlZCEzLjqe2mwGdX3lyJvERnVUFZRhctkC9DN32OcKU6jrg/1r53QUMynHx0 Yv1RNrEbLIfa3S8mQnZqNYcHULO+BPScdIxwCwQ0= 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 5.3 089/148] ima: always return negative code for error Date: Thu, 10 Oct 2019 10:35:50 +0200 Message-Id: <20191010083616.736538919@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@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 d4c7b8e1b083d..7532b062be594 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -268,8 +268,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