Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2082359ybp; Thu, 10 Oct 2019 01:52:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzes6fz8UqMYVMTLx5X2kCdhqRi4e7hkfZvvCklXuUKEouQ+jyof0XXO//SvO8jvE+CxPuo X-Received: by 2002:a17:906:520a:: with SMTP id g10mr6964225ejm.85.1570697569138; Thu, 10 Oct 2019 01:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570697569; cv=none; d=google.com; s=arc-20160816; b=ZCbnScgCMWa1Ek4QJxgIYogUSJF0ad9vRwzuklxT5QIIgqRXCgUCM8pQVtSqOtV7ng DVFxXXrEz1zr/zhuucgC5Pn6A8sRZSxUeRfW2upx1E3GpqEo68PPSeNIaHwk61NUIVY8 +KeosOuVciuQWKksHJxo46O6iPLG0mkOMP3jzFFHhN6QBx6pI/qxPZg6m+YgjyupC98Q P7RtjEN1mD0icQphXpR26PJxy7UG5hQMlSG67H4xckGLAK0uKpHyKpzCsQNhNl9p5XX5 HUb19wUhSmB1HgRwXELKUCZpyIxql5ZnccYHKF584xXNoYPGn3Tp/W0m1Ph5ah8CPJiG lLKQ== 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=mPvf1TgZtlT+qxqZ5xunULIpQH5P+W5TmRg4zQC6m8E=; b=sMhxV6gY+t8p2FCmR5IBej6TH4bHMFnFVz0vEgjcm5LdCyYHmzJiOOQY7uH+GU8IhA etmb3Z28La7CvayS+8pSGcRwdoRS2GOkK7dL1+ysBeieYqTIQwklm5PBcstKJTa3FblS 4aKVn6f1wH2k/o6bkFH/hn+M5dEKvxFCLRtajxM7/KVEeIU5E/PglRv0H2W+3O9DQT2y ldvFjo/BAPYp+TpHxHsLC5GhTcNCAeyjn1bVMBWKrrcpVXAxtBRwEsDdlbAQoaf1LgbE XpEyseah58kT2qOEdFZLjnf/7jUsfcz3byTA6o/zKGVmoIqwfDRSb3xYUKMm/8DLhMkl bgsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fbLOvx0M; 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 c12si3273290edb.394.2019.10.10.01.52.26; Thu, 10 Oct 2019 01:52:49 -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=fbLOvx0M; 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 S2390252AbfJJIwX (ORCPT + 99 others); Thu, 10 Oct 2019 04:52:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:60208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389485AbfJJIwU (ORCPT ); Thu, 10 Oct 2019 04:52:20 -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 016CC2064A; Thu, 10 Oct 2019 08:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570697539; bh=LZt8K+pFKJyJFvN9uH562Rpkc7q8eYhurxMZU2lrw3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fbLOvx0MKJ1Z0i7h9/FqXyBibLoOR2rX02IDE+mkQ57akBmLnqnIgMMLrfEKnhwC8 JjjTH4ZxDi0+vuCJ0YNV1fKaWR1KxEmtMRUfl5iuhwFc6wSAhjbVBZJsmQtEYD5DVe Bm8tfG1Fe5Nholc6D9cePwbW5+4DPQBgrdRyeBbg= 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.14 28/61] ima: always return negative code for error Date: Thu, 10 Oct 2019 10:36:53 +0200 Message-Id: <20191010083507.117565530@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083449.500442342@linuxfoundation.org> References: <20191010083449.500442342@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 af680b5b678a4..06b0ee75f34fb 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -293,8 +293,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