From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=14.137.139.154 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796213793; b=1zE5NVsZYj/7qUuqU7wDhuHjwLVDtmGtvmpzm5alCaiJ180m/ERKueXKbaT30wxqdzrE 1Dvt4qG145W3hbjjf8sdQm+rBtGM0J0YJxSckuABCfPHxaxyulihnY6+Qfbr9FLwg5aol YliHqcSpKq35IFMbdnuKlqGCPFEPeacfI7Lc8xBqvBeBzGoK49hx/lSMme8mO91lYtOXo 6HeNpWXLcnmWhS8QcGTiz117SdfBGTYKSo5EVwa9Ij/sI210FOXjz+n0CEcZ9hzhu00ur 9jpy7tJ0yzpae6lPQKV0lgVvaYeyV29kx+L4UbWBnHRMwAY7V29VTawsAZvAZc1VfAg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796213793; h=DMARC-Filter:Received:Received:Received:Message-ID:Subject:From:To: Cc:Date:In-Reply-To:References:Content-Type:Content-Transfer-Encoding: User-Agent:MIME-Version:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=HyK7IfjUYBPtGb48bXxhsJiRT8Il+QaEdxyfwGC7F0Q=; b=uYkP754gHkmJDwUTLv6KezUx2lWg4D0ozlkrw/wyU8Vv4qqK/V3Xavr3lWFaSiZvBXJ5 gaqpPzrWDU8w5sRaTGJwxrFweeJlxy9tuNfUQGp2jy1juXjgJloC7eyYsRNa4JijbIRBO QOLORCMiAUvMwsDK/87CmLSncazl77/zHxYlszdK98f4Xypn0dEFxO6AeFMrt5ZQBnym7 CAIZR3fxTycvcp5QdTLPdb9hG5P0fGIlLLl3YXpgQvTy3h8TA3i7zRpSy0tPGG+AldIxv SGHzeQHpkA4h+YuCT2/lqPtIcBU9giQJmsUigWhdVwXmtPV9h0ot3ijul+QqlqQladQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.remote-ip=14.137.139.154 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86B3C606A331; Wed, 2 Dec 2026 12:16:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 86B3C606A331 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.224.196]) by frasgout12.his.huawei.com (SkyGuard) with ESMTPS id 4jfcCt6T2YztK0q; Wed, 2 Dec 2026 20:15:38 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.218]) by mail.maildlp.com (Postfix) with ESMTP id 28CC3404A4; Wed, 2 Dec 2026 20:16:28 +0800 (CST) Received: from [10.204.63.22] (unknown [10.204.63.22]) by dep2_app2 (Coremail) with UTF8SMTPA id 2hC2B0BWY1EUDBBrv1A+AA--.1121S2; Wed, 02 Dec 2026 13:16:27 +0100 (CET) Message-ID: <00ee31e280b2929e81ca35dbca7d43762bc7645b.camel@huaweicloud.com> Subject: Re: [PATCH] ima: allocate the new hash table before detaching staged measurements From: Roberto Sassu To: Cong Nguyen , Mimi Zohar , Roberto Sassu Cc: Dmitry Kasatkin , Eric Snowberg , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 02 Dec 2026 13:16:17 +0100 In-Reply-To: <20261127075732.252471-1-congnt264@gmail.com> References: <20261127075732.252471-1-congnt264@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-CM-TRANSID:2hC2B0BWY1EUDBBrv1A+AA--.1121S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WF4UWF1kXryfCr18JF4Utwb_yoW8tr17pa 9a9340k3yrtrWxtryrG34Syr93G3ykCr1UGw4UJ34xCF1fXF1j9rs0kryI9Fs5GrWFqa1r tw4aqrsxAa1qyaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUylb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWUJVW8JwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUotCzDUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQABDWsPjU5jtwAAs+ On Fri, 2026-11-27 at 14:57 +0700, Cong Nguyen wrote: > ima_queue_staged_delete_all() moves the staged measurements to a local > list and clears the staged counters before it allocates the replacement > hash table with ima_alloc_replace_htable(). If that allocation fails, the > function returns -ENOMEM with the entries already detached from > ima_measurements_staged and never freed, because ima_queue_delete() is > only reached on success. The entries are then on no list, and a retry > finds nothing to delete. >=20 > Allocate the hash table first, so that the -ENOMEM return leaves the > staged state unchanged. Both steps run under ima_extend_list_mutex. >=20 > Fixes: c26d9d9246cc ("ima: Add support for flushing the hash table when s= taging measurements") > Signed-off-by: Cong Nguyen Reviewed-by: Roberto Sassu Thanks Roberto > --- > security/integrity/ima/ima_queue.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) >=20 > diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/= ima_queue.c > index 67782c004cdf..d58b33950bcc 100644 > --- a/security/integrity/ima/ima_queue.c > +++ b/security/integrity/ima/ima_queue.c > @@ -377,14 +377,6 @@ int ima_queue_staged_delete_all(void) > return -ESTALE; > } > =20 > - list_replace(&ima_measurements_staged, &ima_measurements_trim); > - INIT_LIST_HEAD(&ima_measurements_staged); > - > - atomic_long_set(&ima_num_records[BINARY_STAGED], 0); > - > - if (IS_ENABLED(CONFIG_IMA_KEXEC)) > - binary_runtime_size[BINARY_STAGED] =3D 0; > - > if (ima_flush_htable) { > old_queue =3D ima_alloc_replace_htable(); > if (IS_ERR(old_queue)) { > @@ -393,6 +385,14 @@ int ima_queue_staged_delete_all(void) > } > } > =20 > + list_replace(&ima_measurements_staged, &ima_measurements_trim); > + INIT_LIST_HEAD(&ima_measurements_staged); > + > + atomic_long_set(&ima_num_records[BINARY_STAGED], 0); > + > + if (IS_ENABLED(CONFIG_IMA_KEXEC)) > + binary_runtime_size[BINARY_STAGED] =3D 0; > + > mutex_unlock(&ima_extend_list_mutex); > =20 > if (ima_flush_htable) {