From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796322412; b=IonZZvumKEUpxEt9IEnyzbIg22KT25GJKiAp2xrBclaZA08Kt8/gcofBEQkaP3f2m+NP VPU0Vzo9Z5FUOeIbPHwZ+5BWye/XbgUZY6NZ5CX2vDg/4eLeFHaoSCenh+2qLjsj8yq/3 /JTwtNmGmjid1VjB/8rQZpw0ItAjqrpu3Z5OF4yRKt+b5pvVDHUItYuZc/7ZjIMH5E/w5 aqIfdnS8ewQ3SEvNMWghaQ+ykXyOh36dQ1AXBL1KVSDgTeCIe28hXaGSX0NVBHzJVCmJc +N4l6MuX7zxZzc48Jp6BpBjf3EglrZcshFsP4qjKNne2b0B45ejVfH2dt8S/8PhvPcw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796322412; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=wsMq3dLESqMjn2gxQIPpy9obLS7r25zbZV1I3J2QEW8=; b=jlkPqKwineloR1NuBiSNocjgyXsdFL3+T637txsAn59tO3jHKIDVwbWY7ejAxoNoBaOh FInSitODwhAreuTunZco66qEDdliyvSwnNP/iXqmc1muoNivk0k0kR342rKK/LAEcwKQ2 7Ef2X2WBB1H2u62SUykTI23TdGuBoMh3am479CoQw02702vQY1FpxyNQcnxmYTrwg2mri qf/ampI8fl09ISUzAdwCojwHoPL36i6EVf8bwpYERXMbGF2hOX6sH4X87C++JT94mH9K0 rY8Z5ZtCdEOdcdRqlzOqSGwtmb4mgeOikbwvl4gt/wW51LRRu6A4DSxLHwTumYwtk9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Cyu21Wbx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 13DAA606A322 for ; Thu, 3 Dec 2026 18:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Cyu21Wbx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C7AC1F00893 for ; Thu, 3 Dec 2026 18:26:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796322411; bh=wsMq3dLESqMjn2gxQIPpy9obLS7r25zbZV1I3J2QEW8=; h=From:Subject:Reply-To:Cc:In-Reply-To:References:Date; b=Cyu21WbxKwDSKD0UQ22a6AVjZ8qUlteuZ055jevHRjLH6XdTVxHM1F/chXMulsXEy ACdUm7i88RlXSNXNcN+EPTz45B/ORLQzCIakAVmL3JweqoNUrOYFRJzFOJswhU0zcb edrN3ufSZ9wRmMD2eHobWA0PNdJiV+uHpvWd6NSdzG8b0H8jF7yHeLziFe3Q0WbSEP GsGaYHojamLclnmPX3Gk1Z4On1foPdE5r6K9R8b7nBLYs8mcoA+VrsnT2Nf0rdnQA7 R3+Sgjf16W8Fd//LdNc3WLQr/2VfolfaoH5A7CCtuvUnQawJR0jVdP3eVWKbLPt4y1 MjRT74XHeAkpw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] audit: clear borrowed LSM pointers before duplicating rule fields Reply-To: sashiko-reviews@lists.linux.dev Cc: =?utf-8?b?b3BlbiBsaXN0OkFVRElUIFNVQlNZU1RFTQ==?= In-Reply-To: <20261203172113.2281383-1-hdthky0@gmail.com> References: <20261203172113.2281383-1-hdthky0@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 18:26:51 +0000 X-Mailing-List: audit@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] audit: redundant second pass and duplicated LSM switch in audit_dupe_rule() -- commit 8603e73a37f90ece738b607175e433adc3c62e0f Author: Xingyuan Mo audit: clear borrowed LSM pointers before duplicating rule fields This commit clears lsm_str and lsm_rule on LSM-typed fields right after memcpy() in audit_dupe_rule() so that an error during field duplication does not double-free pointers still owned by the original rule. > diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c > index cf91ba6f3617b..218cc64f779a3 100644 > --- a/kernel/auditfilter.c > +++ b/kernel/auditfilter.c > @@ -883,6 +883,23 @@ struct audit_entry *audit_dupe_rule(struct audit_kru= le *old, > new->tree =3D old->tree; > memcpy(new->fields, old->fields, sizeof(struct audit_field) * fcount); > =20 > + for (i =3D 0; i < fcount; i++) { > + switch (new->fields[i].type) { > + case AUDIT_SUBJ_USER: > + case AUDIT_SUBJ_ROLE: > + case AUDIT_SUBJ_TYPE: > + case AUDIT_SUBJ_SEN: > + case AUDIT_SUBJ_CLR: > + case AUDIT_OBJ_USER: > + case AUDIT_OBJ_ROLE: > + case AUDIT_OBJ_TYPE: > + case AUDIT_OBJ_LEV_LOW: > + case AUDIT_OBJ_LEV_HIGH: > + new->fields[i].lsm_str =3D NULL; > + new->fields[i].lsm_rule =3D NULL; > + } > + } > + > /* deep copy this information, updating the lsm_rule fields, because > * the originals will all be freed when the old rule is freed. */ > for (i =3D 0; i < fcount; i++) { [Severity: Low] Can this avoid the extra pass and duplicated 10-case LSM switch? audit_init_entry() already zero-allocates new->fields, and the loop below never inspects entries past index i. Copying new->fields[i] =3D old->fields[i] in the existing loop and clearing lsm_str and lsm_rule before audit_dupe_lsm_field() fixes the double free in one pass. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203172113.2281= 383-1-hdthky0@gmail.com?part=3D1