Audit system development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: "open list:AUDIT SUBSYSTEM" <audit@vger.kernel.org>
Subject: Re: [PATCH] audit: clear borrowed LSM pointers before duplicating rule fields
Date: Thu, 03 Dec 2026 18:26:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-248382@kernel.org> (raw)
In-Reply-To: <20261203172113.2281383-1-hdthky0@gmail.com>

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 <hdthky0@gmail.com>

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_krule *old,
>  	new->tree = old->tree;
>  	memcpy(new->fields, old->fields, sizeof(struct audit_field) * fcount);
>  
> +	for (i = 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 = NULL;
> +			new->fields[i].lsm_rule = 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 = 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] =
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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203172113.2281383-1-hdthky0@gmail.com?part=1

      reply	other threads:[~2026-12-03 18:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:21 [PATCH] audit: clear borrowed LSM pointers before duplicating rule fields Xingyuan Mo
2026-12-03 18:26 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-248382@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=audit@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox