Received: by 10.213.65.68 with SMTP id h4csp1222613imn; Wed, 14 Mar 2018 13:22:24 -0700 (PDT) X-Google-Smtp-Source: AG47ELt7sMALZCeZrOZxohheKVl97McBu+x8I4g7jQAOaeyDEIj7cUJnCUzzIfvh/AQQdXlx1vgf X-Received: by 10.99.110.133 with SMTP id j127mr4799571pgc.79.1521058944774; Wed, 14 Mar 2018 13:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521058944; cv=none; d=google.com; s=arc-20160816; b=HJksDrtWBM/bmaQdMLFy4ZYE3zfAU6deq5u3WDpzkT0HNBg6gEIjNHn/DOkAp+JuYN dNozUKwijpcXYseT6R0ITBxuGPxrIQ1z3JxYjrBNRdmntaEf81DffppcZGb8cSeeUQ2q 2cxhdBBLFXrQDJ85d5hRQrdyr6tQfANc2N5xd9sleLRRbzbW+4QPwXHW42SG9dc798Hf 544LHcngf2l0/7p5mkdRZ5foi/IRShC64ot1zk1H28KXggLtt36wE8Mkqc4jSS2fWmvK UrSTe0fkLopVg0Eb/uReUYpFRy/VLpsVDfk1c0HoJlQr83KWlt4Jb6GJ3LQi2nO3fw2W Dxog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=iyP9FnxHnHLdav6E4fmT37NplPIxbw4UEUDwBAwOdaU=; b=lNueHISTU9/MY9g1Z7t+rDI1d/VjIOpyT3jBiebgQaMpCaI1SOkhRlYYf1Z7oFl+q3 pOkamRYj8ezMQkSBR89iReQAPiSXI3n0hrWXP5txmKrFa43r7ZAA5wFrd/7l46LfMSpJ 8/SlTduuh2xOABr9fd5RUFOkZZ1Iwe1EYp5WcmzucazqJbTWlxcxQf7KmBl0p5aTG0so n77gXW962BEXiImJWGXXBh2HI8qPTDLGPP9LITHgD5IJLCmb/axqM6RWQ6L1Cv0+DtK+ EmPEhk9hye7qge2g8/NqHCHxdf1zRXb7C21Qh1002NkoiLuR7iVDS2J16HVXzny4EhhC hAvQ== 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 x4si2607414pfx.350.2018.03.14.13.22.10; Wed, 14 Mar 2018 13:22:24 -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; 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 S1752181AbeCNUUt (ORCPT + 99 others); Wed, 14 Mar 2018 16:20:49 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50112 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752081AbeCNUUr (ORCPT ); Wed, 14 Mar 2018 16:20:47 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2EKJveT022198 for ; Wed, 14 Mar 2018 16:20:47 -0400 Received: from e19.ny.us.ibm.com (e19.ny.us.ibm.com [129.33.205.209]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gq6y3hfa0-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 14 Mar 2018 16:20:46 -0400 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Mar 2018 16:20:45 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Mar 2018 16:20:42 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2EKKfww50331762; Wed, 14 Mar 2018 20:20:41 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 89485AC043; Wed, 14 Mar 2018 16:21:57 -0400 (EDT) Received: from morokweng.localdomain.com (unknown [9.85.137.56]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id E9DE5AC03A; Wed, 14 Mar 2018 16:21:55 -0400 (EDT) From: Thiago Jung Bauermann To: linux-integrity@vger.kernel.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, James Morris , "Serge E. Hallyn" , Mimi Zohar , Dmitry Kasatkin , Thiago Jung Bauermann Subject: [PATCH 3/4] ima: Improvements in ima_appraise_measurement() Date: Wed, 14 Mar 2018 17:20:19 -0300 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180314202020.3794-1-bauerman@linux.vnet.ibm.com> References: <20180314202020.3794-1-bauerman@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18031420-0056-0000-0000-0000042D8CC5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008674; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000254; SDB=6.01003063; UDB=6.00510447; IPR=6.00782394; MB=3.00020035; MTD=3.00000008; XFM=3.00000015; UTC=2018-03-14 20:20:44 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031420-0057-0000-0000-0000086F8DCB Message-Id: <20180314202020.3794-4-bauerman@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-14_11:,, 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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803140218 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mimi Zohar Replace nested ifs in the EVM xattr verification logic with a switch statement, making the code easier to understand. Also, add comments to the if statements in the out section and constify the cause variable. Signed-off-by: Mimi Zohar Signed-off-by: Thiago Jung Bauermann --- security/integrity/ima/ima_appraise.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index 0c5f94b7b9c3..dd10ecbdce45 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -215,7 +215,7 @@ int ima_appraise_measurement(enum ima_hooks func, int xattr_len, int opened) { static const char op[] = "appraise_data"; - char *cause = "unknown"; + const char *cause = "unknown"; struct dentry *dentry = file_dentry(file); struct inode *inode = d_backing_inode(dentry); enum integrity_status status = INTEGRITY_UNKNOWN; @@ -241,16 +241,20 @@ int ima_appraise_measurement(enum ima_hooks func, } status = evm_verifyxattr(dentry, XATTR_NAME_IMA, xattr_value, rc, iint); - if ((status != INTEGRITY_PASS) && - (status != INTEGRITY_PASS_IMMUTABLE) && - (status != INTEGRITY_UNKNOWN)) { - if ((status == INTEGRITY_NOLABEL) - || (status == INTEGRITY_NOXATTRS)) - cause = "missing-HMAC"; - else if (status == INTEGRITY_FAIL) - cause = "invalid-HMAC"; + switch (status) { + case INTEGRITY_PASS: + case INTEGRITY_PASS_IMMUTABLE: + case INTEGRITY_UNKNOWN: + break; + case INTEGRITY_NOXATTRS: /* No EVM protected xattrs. */ + case INTEGRITY_NOLABEL: /* No security.evm xattr. */ + cause = "missing-HMAC"; + goto out; + case INTEGRITY_FAIL: /* Invalid HMAC/signature. */ + cause = "invalid-HMAC"; goto out; } + switch (xattr_value->type) { case IMA_XATTR_DIGEST_NG: /* first byte contains algorithm id */ @@ -316,17 +320,20 @@ int ima_appraise_measurement(enum ima_hooks func, integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, filename, op, cause, rc, 0); } else if (status != INTEGRITY_PASS) { + /* Fix mode, but don't replace file signatures. */ if ((ima_appraise & IMA_APPRAISE_FIX) && (!xattr_value || xattr_value->type != EVM_IMA_XATTR_DIGSIG)) { if (!ima_fix_xattr(dentry, iint)) status = INTEGRITY_PASS; - } else if ((inode->i_size == 0) && - (iint->flags & IMA_NEW_FILE) && - (xattr_value && - xattr_value->type == EVM_IMA_XATTR_DIGSIG)) { + } + + /* Permit new files with file signatures, but without data. */ + if (inode->i_size == 0 && iint->flags & IMA_NEW_FILE && + xattr_value && xattr_value->type == EVM_IMA_XATTR_DIGSIG) { status = INTEGRITY_PASS; } + integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, filename, op, cause, rc, 0); } else {