Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6590411ybx; Mon, 11 Nov 2019 11:26:57 -0800 (PST) X-Google-Smtp-Source: APXvYqw3t5WirSPiKM5fZGM/diAz+O0LNIIUywkdmOsE6XjK6+WNaBNzZQN8f8F15zyi+Z/VPrhv X-Received: by 2002:a17:907:20b8:: with SMTP id pw24mr12466672ejb.28.1573500417118; Mon, 11 Nov 2019 11:26:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573500417; cv=none; d=google.com; s=arc-20160816; b=pT05+GBKCxByZkyHDapTf/1D+fVpOGo/jnk+KO7D6H0GgfPx2srQ04zGmi429/EWEk K9LeHBOoSfrPtjjkfAbIB/+bZX7LRNIBy+JgFDUA9OmEkShZMs+OuSdTfX1M5erHi4OI 6KyKgywfb/Br6K65y3HwlHaymDq0jxWyQIULs7fqAdfHKIwop75juBBtmv5CZln/QUm5 0ShEGwX2ciCa/6UVeHbXIMr8wyacafxSjxU+5LK22W316gV7jSDMggICXeJEh/bN7Heo Dj78Aa0DBw/K0KK3IEyX1NrSYwSSGaTASn4llma8NSnhMPTc7laswoUew+n95G43xZsy DiYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=xzp5uaODdVpKghsuQ2G1KKx1sTzI2ttVJrqdjlTepqY=; b=Pp+McVVW0DZoji7QKXNkt/nm0ph+kpTi4JnnTBTvHV8lvMNlV55C/rhtu/9tnZfp1N Ouxclf5S8y3PwS0UzmPZcP2dn+e1A84gmOZ13LcV/sQJ+31RoVtDFVYFmGLrYjRmncmt 6Y7UZXufeb+cIfzCOtj/vouM8k550vHCTChvOutihae/uAs8HgAV527ra+V9vTGGsWTA Mc7na6HEDdZVCioufgmEbBKrusyyXHtzTJH7K+Ocx+tglqSOyExNeI5slWSnpzA3nsNN 4Dk/TC0qm8kjQ9VoVM2FMi/a2ei7TQXlEmViHne8JH48TKbQdbXy4PxIlzia3G9yUla5 ptiA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f45si11449831ede.381.2019.11.11.11.26.32; Mon, 11 Nov 2019 11:26:57 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727506AbfKKTYR (ORCPT + 99 others); Mon, 11 Nov 2019 14:24:17 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47104 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726927AbfKKTYR (ORCPT ); Mon, 11 Nov 2019 14:24:17 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id xABJNR1N104389 for ; Mon, 11 Nov 2019 14:24:15 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2w7bqc4u5j-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 11 Nov 2019 14:24:15 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Nov 2019 19:24:13 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 11 Nov 2019 19:24:10 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xABJO9xR49873012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Nov 2019 19:24:09 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EDAFA4C04A; Mon, 11 Nov 2019 19:24:08 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 404B84C044; Mon, 11 Nov 2019 19:24:08 +0000 (GMT) Received: from oc3746452103.ibm.com (unknown [9.60.73.196]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 11 Nov 2019 19:24:08 +0000 (GMT) From: Patrick Callaghan To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sascha Hauer , Patrick Callaghan , Mimi Zohar Subject: [PATCH] ima: avoid appraise error for hash calc interrupt Date: Mon, 11 Nov 2019 14:23:48 -0500 X-Mailer: git-send-email 2.8.3 X-TM-AS-GCONF: 00 x-cbid: 19111119-0012-0000-0000-00000362BE21 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19111119-0013-0000-0000-0000219E2A8E Message-Id: <20191111192348.30535-1-patrickc@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-11-11_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911110173 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The integrity_kernel_read() call in ima_calc_file_hash_tfm() can return a value of 0 before all bytes of the file are read. A value of 0 would normally indicate an EOF. This has been observed if a user process is causing a file appraisal and is terminated with a SIGTERM signal. The most common occurrence of seeing the problem is if a shutdown or systemd reload is initiated while files are being appraised. The problem is similar to commit (ima: always return negative code for error) that fixed the problem in ima_calc_file_hash_atfm(). Suggested-by: Mimi Zohar Signed-off-by: Patrick Callaghan --- security/integrity/ima/ima_crypto.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 73044fc..7967a69 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -362,8 +362,10 @@ static int ima_calc_file_hash_tfm(struct file *file, rc = rbuf_len; break; } - if (rbuf_len == 0) + if (rbuf_len == 0) { /* unexpected EOF */ + rc = -EINVAL; break; + } offset += rbuf_len; rc = crypto_shash_update(shash, rbuf, rbuf_len); -- 2.8.3