Received: by 10.213.65.68 with SMTP id h4csp626734imn; Fri, 16 Mar 2018 13:43:38 -0700 (PDT) X-Google-Smtp-Source: AG47ELu6tx3bbgeIV8/NHd1P0YePRRVSf6dYQ2cL8S/06OBRlBQOCdP5+fiWQuW2r3yWLoxJ95We X-Received: by 10.98.41.134 with SMTP id p128mr2756124pfp.120.1521233018886; Fri, 16 Mar 2018 13:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521233018; cv=none; d=google.com; s=arc-20160816; b=ZacuYNoZPM/5HKEVMu8oXj01/TgGjESRsPgO8h3lw/l4fAV1d6dzXOu0iycnYfwVGh RcoeYQBMp8ZkREzhELvkwOBosNampPP0+WgT2PeHEYQ5PRWrG74YEsXwlATEtCcwfsYJ y4XkP4qWhKm2+EMG/Ht9bfvNh1F8JHmFqkgCalkmrmHo1bxwY8Yuy+OKyajA9yT+N77x XYTaiSXFgkS1YKbn92ewA4OQbtkBjhGCn3vwag0mzND+VBEJD5bRmPgGJBaUjW5CdbHl flH6x/2iAmat8UHL1NdrXXp5cxeA9tQ2vsGAVBhWBONK69W6Mx4C7Igv5Zfpe2bRUG9y Jq7A== 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=KE/aliTK+XW/+snaBDPxuTBxghA70NsqJPOyN3BxRTE=; b=yFNQwAdCBmvI7jadg0iylNmxA+VUOo8JDxlWuIrAFcmO4C8WMSfGEQMmthjmgvx09T /CZF69Tfl4KmR3+o6h+BQMIzoY6Y+Z2dgEjS6KBhbREcGr7E9GBHfDsYwzpAgAUpLHQI dJmDfJDTNPbt5BZMJJ9KPoNKkSAi8wgLt+kcIy65Ysq5TPRJbciJBTPsAauyXy40IpcS h5xgtfRx/y/yVNZQnVyOJsLK40I4xncNlJ316MsmMntvJD0NAxmSG5JGb+ai/ryRWfb1 ZbUUUDtBO5ehAL21cgywsrJGKeU3NsugKBs7JaqIewgW2kRIyj0NJSKUOIkPqqjqrexO QcJQ== 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 v10si5469533pgs.164.2018.03.16.13.43.20; Fri, 16 Mar 2018 13:43:38 -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 S1753701AbeCPUmX (ORCPT + 99 others); Fri, 16 Mar 2018 16:42:23 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51258 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753569AbeCPUjv (ORCPT ); Fri, 16 Mar 2018 16:39:51 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2GKdZaT001876 for ; Fri, 16 Mar 2018 16:39:50 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 2grmb9spp1-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Fri, 16 Mar 2018 16:39:50 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 16 Mar 2018 14:39:49 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 16 Mar 2018 14:39:44 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2GKdiMW11272454; Fri, 16 Mar 2018 13:39:44 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2026B7803F; Fri, 16 Mar 2018 14:39:44 -0600 (MDT) Received: from morokweng.localdomain.com (unknown [9.85.199.230]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 0693378038; Fri, 16 Mar 2018 14:39:39 -0600 (MDT) From: Thiago Jung Bauermann To: linux-integrity@vger.kernel.org Cc: linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , David Howells , David Woodhouse , Jessica Yu , Herbert Xu , "David S. Miller" , "AKASHI, Takahiro" , Thiago Jung Bauermann Subject: [PATCH v6 05/12] integrity: Introduce integrity_keyring_from_id() Date: Fri, 16 Mar 2018 17:38:30 -0300 X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316203837.10174-1-bauerman@linux.vnet.ibm.com> References: <20180316203837.10174-1-bauerman@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18031620-0008-0000-0000-00000977E345 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008686; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000254; SDB=6.01004029; UDB=6.00511020; IPR=6.00783317; MB=3.00020079; MTD=3.00000008; XFM=3.00000015; UTC=2018-03-16 20:39:48 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031620-0009-0000-0000-0000466BDD45 Message-Id: <20180316203837.10174-6-bauerman@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-16_13:,, 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-1803160243 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org IMA will need to obtain the keyring used to verify file signatures so that it can verify the module-style signature appended to files. Signed-off-by: Thiago Jung Bauermann --- security/integrity/digsig.c | 28 +++++++++++++++++++++------- security/integrity/integrity.h | 6 ++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c index 6f9e4ce568cd..e641a67b9fc7 100644 --- a/security/integrity/digsig.c +++ b/security/integrity/digsig.c @@ -48,11 +48,10 @@ static bool init_keyring __initdata; #define restrict_link_to_ima restrict_link_by_builtin_trusted #endif -int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, - const char *digest, int digestlen) +struct key *integrity_keyring_from_id(const unsigned int id) { - if (id >= INTEGRITY_KEYRING_MAX || siglen < 2) - return -EINVAL; + if (id >= INTEGRITY_KEYRING_MAX) + return ERR_PTR(-EINVAL); if (!keyring[id]) { keyring[id] = @@ -61,17 +60,32 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, int err = PTR_ERR(keyring[id]); pr_err("no %s keyring: %d\n", keyring_name[id], err); keyring[id] = NULL; - return err; + return ERR_PTR(err); } } + return keyring[id]; +} + +int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, + const char *digest, int digestlen) +{ + struct key *keyring; + + if (siglen < 2) + return -EINVAL; + + keyring = integrity_keyring_from_id(id); + if (IS_ERR(keyring)) + return PTR_ERR(keyring); + switch (sig[1]) { case 1: /* v1 API expect signature without xattr type */ - return digsig_verify(keyring[id], sig + 1, siglen - 1, + return digsig_verify(keyring, sig + 1, siglen - 1, digest, digestlen); case 2: - return asymmetric_verify(keyring[id], sig, siglen, + return asymmetric_verify(keyring, sig, siglen, digest, digestlen); } diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h index 79799a0d9195..2d245f44ca26 100644 --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h @@ -150,6 +150,7 @@ int integrity_kernel_read(struct file *file, loff_t offset, #ifdef CONFIG_INTEGRITY_SIGNATURE +struct key *integrity_keyring_from_id(const unsigned int id); int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, const char *digest, int digestlen); @@ -157,6 +158,11 @@ int __init integrity_init_keyring(const unsigned int id); int __init integrity_load_x509(const unsigned int id, const char *path); #else +static inline struct key *integrity_keyring_from_id(const unsigned int id) +{ + return ERR_PTR(-EINVAL); +} + static inline int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen, const char *digest, int digestlen)