Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2921454rdb; Tue, 13 Feb 2024 00:58:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+6OkRwKVTd75odQ8PMHFt13GixLkv7A0wBkOm3QVIUUZQ0rddvstmHiBM1ZF1+ywY8yOJ X-Received: by 2002:a17:906:3903:b0:a37:fb7d:6f21 with SMTP id f3-20020a170906390300b00a37fb7d6f21mr6382714eje.51.1707814697938; Tue, 13 Feb 2024 00:58:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707814697; cv=pass; d=google.com; s=arc-20160816; b=twnrel85m+Azpm8/PANXsmWo8vkF2mlZV55ZWgHvIEv2HR+G/MqGwmvOXnH+TD9xGi NibpzmBat+JqZDEhizvEEUqC8bObUg8ZoMynXVsJojOCK3an3JCdYYlyoQCuZc1E42z6 LBf0GzEZx1bNOfdLKL7Y6NBanQyMcYcb1636BUTYMXtojEDasfwrWcVttwuA9P2Chvbx ni6XRS5LJY6gxvVOIRxmiQgasmwA9CJftKFQnyQAePUi0eu7a1/SKx6PSXi2IINRvMXp qCqUeJ3tfD9/0NVKXlpQuStf5kU/y5MQD20dwldlR5rXVQfUg9+lPrjOL7FNFxpqBZoU KXxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id; bh=qYoTICm348mVJ3C4S3t4WB1b0e9wTJ28ihamcPm8/gs=; fh=MZGK4IMnVKVFF+GtgkseWhf2GKxwCGYoRtFgaj5n3r0=; b=guQtoyg0u9jo7bmZsKfO+1dVSMxK18zEf4C5xLq1Fsgqu0hpw6+2fa5B/s6hUD/NXp W5+YX6JC+XiNvadAvPauxU1e7ZFUPsQ8J5IbTT9VRkWBpM0pe5un0Ox2igaVqkYQBpOi wI3fiH7N3+eLaDkYztTg9NOGpSMx+0s91xqPVen5t/S07c8MdsOl6QFaEzTJgdyf8mfm ZBgw1zi77xadNc8F7U/XD8csPOrMsYgfiqdLboMmgevttupJhDVdAVfhmWEf7/EPIXYV QinDhm1OSzCEcnQFcyKkmhr/uzwSAJRMAaiCo+sSoLOduQJrv7jaqBxIAQpW6nSOxFq8 fuPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-nfs+bounces-1906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1906-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCW2x182kQ4H8IK/WSjoBaxX9tNmqWZ8zw+pvrLimV6SUq/cSY/L36iSXkXqrZyHTLZR90dY2s01blrhXP2ih2OVGHKSe2Mlif24cciQ6Q== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y9-20020a1709063da900b00a3cce6bdc37si1033137ejh.135.2024.02.13.00.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:58:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-1906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-nfs+bounces-1906-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1906-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AC3F71F243FD for ; Tue, 13 Feb 2024 08:58:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31A13224CF; Tue, 13 Feb 2024 08:57:37 +0000 (UTC) X-Original-To: linux-nfs@vger.kernel.org Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C36A22611; Tue, 13 Feb 2024 08:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707814657; cv=none; b=Jh/bHSlhgFaivI7wPGYfZIPelqBR+yulIuFKiMecYhaAImGuJbcbbXsHDZcnLk2/t6lvR96vH1TvvctK3v20k6TAAAaIAFvs+18gVzWdc6iHk82hiH4fUgM9gdbH65YV8EIAarIWibAwlsAv5cvfSXUi6qirWXcCouPYp0qwdvo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707814657; c=relaxed/simple; bh=0FHVuXSnOE5TFanr4pfTOtnrDKxeRonirC9x/EUdZ3I=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=MrigbQprRU1wL8QBd+VQc/0B6pNkylymZahq70ChfryBMyZ5T9mwG/yEvlJVSM5Z/rpMjFj99+XnBpAZHajZGxl0j7BcbtjjCXEQb2humF0XMJkqzfVBj2DwauckyNWdi9aRqrM8FboX0egA17dsRrG5I7qHVVpjbEzkBFQUjag= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.51]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4TYvvq0G2Dz9v7VH; Tue, 13 Feb 2024 16:42:15 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id 1A6BC1405A1; Tue, 13 Feb 2024 16:57:24 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwDHsibjLstlJFJmAg--.44640S2; Tue, 13 Feb 2024 09:57:23 +0100 (CET) Message-ID: Subject: Re: [PATCH v9 19/25] integrity: Move integrity_kernel_module_request() to IMA From: Roberto Sassu To: Stefan Berger , Paul Moore Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, jmorris@namei.org, serge@hallyn.com, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, eric.snowberg@oracle.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com, shuah@kernel.org, mic@digikod.net, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Roberto Sassu Date: Tue, 13 Feb 2024 09:57:03 +0100 In-Reply-To: <7940b9d0-3133-4b08-b397-ad9ee34e3b34@linux.ibm.com> References: <20240115181809.885385-1-roberto.sassu@huaweicloud.com> <20240115181809.885385-20-roberto.sassu@huaweicloud.com> <7940b9d0-3133-4b08-b397-ad9ee34e3b34@linux.ibm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID:GxC2BwDHsibjLstlJFJmAg--.44640S2 X-Coremail-Antispam: 1UD129KBjvJXoWxur4xJFy3Kr4UWrWDCF1fXrb_yoW5Gr18pF WrKanYyFWDXrn5Cay8Xw17WrWSgayxCrZxGrn5GrWfWrsY9rnFvF42yF4UuFZakrn7Jr1j 9397Jw1Ivr98Z37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv 6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUOlksDUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAMBF1jj5ZOIgABsA On Mon, 2024-02-12 at 15:28 -0500, Stefan Berger wrote: >=20 > On 2/12/24 12:56, Paul Moore wrote: > > On Mon, Feb 12, 2024 at 12:48=E2=80=AFPM Stefan Berger wrote: > > > On 1/15/24 13:18, Roberto Sassu wrote: > >=20 > > ... > >=20 > > > > +/** > > > > + * ima_kernel_module_request - Prevent crypto-pkcs1pad(rsa,*) requ= ests > > > > + * @kmod_name: kernel module name > > > > + * > > > > + * We have situation, when public_key_verify_signature() in case o= f RSA > + * algorithm use alg_name to store internal information in order t= o > > > > + * construct an algorithm on the fly, but crypto_larval_lookup() w= ill try > > > > + * to use alg_name in order to load kernel module with same name. > > > > + * Since we don't have any real "crypto-pkcs1pad(rsa,*)" kernel mo= dules, > > > > + * we are safe to fail such module request from crypto_larval_look= up(). > > > > + * > > > > + * In this way we prevent modprobe execution during digsig verific= ation > > > > + * and avoid possible deadlock if modprobe and/or it's dependencie= s > > > > + * also signed with digsig. > > >=20 > > > This text needs to some reformulation at some point.. > >=20 > > There is no time like the present. If you have a suggestion I would > > love to hear it and I'm sure Roberto would too. > >=20 >=20 > My interpretation of the issue after possibly lossy decoding of the=20 > above sentences: >=20 > Avoid a deadlock by rejecting a virtual kernel module with the name=20 > "crypto-pkcs1pad(rsa,*)". This module may be requested by=20 > crypto_larval_lookup() while trying to verify an RSA signature in=20 > public_key_verify_signature(). Since the loading of the RSA module may= =20 > itself cause the request for an RSA signature verification it will=20 > otherwise lead to a deadlock. I can be even more precise I guess (I actually reproduced it). Avoid a verification loop where verifying the signature of the modprobe binary requires executing modprobe itself. Since the modprobe iint- >mutex is already held when the signature verification is performed, a deadlock occurs as soon as modprobe is executed within the critical region, since the same lock cannot be taken again. This happens when public_key_verify_signature(), in case of RSA algorithm, use alg_name to store internal information in order to construct an algorithm on the fly, but crypto_larval_lookup() will try to use alg_name in order to load a kernel module with same name. Since we don't have any real "crypto-pkcs1pad(rsa,*)" kernel modules, we are safe to fail such module request from crypto_larval_lookup(), and avoid the verification loop. Roberto