public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: Sabrina Dubroca <sd@queasysnail.net>
Cc: syzbot <syzbot+5cd6299ede4d4f70987b@syzkaller.appspotmail.com>,
	<davem@davemloft.net>, <edumazet@google.com>,
	<herbert@gondor.apana.org.au>, <horms@kernel.org>,
	<kuba@kernel.org>, <linux-kernel@vger.kernel.org>,
	<netdev@vger.kernel.org>, <pabeni@redhat.com>,
	<syzkaller-bugs@googlegroups.com>
Subject: Re: [syzbot] [net?] WARNING in xfrm_state_migrate (2)
Date: Wed, 15 Oct 2025 09:43:12 +0200	[thread overview]
Message-ID: <aO9QkNNkZ1JLnnIl@secunet.com> (raw)
In-Reply-To: <aO5PnU4dhUuzM34e@krikkit>

On Tue, Oct 14, 2025 at 03:26:53PM +0200, Sabrina Dubroca wrote:
> 2025-10-05, 10:39:46 -0700, syzbot wrote:
> > Hello,
> > 
> > syzbot found the following issue on:
> > 
> > HEAD commit:    4b946f6bb7d6 selftests/bpf: Fix realloc size in bpf_get_ad..
> > git tree:       bpf
> > console output: https://syzkaller.appspot.com/x/log.txt?x=13be46e2580000
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=8f1ac8502efee0ee
> > dashboard link: https://syzkaller.appspot.com/bug?extid=5cd6299ede4d4f70987b
> > compiler:       Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
> > 
> > Unfortunately, I don't have any reproducer for this issue yet.
> > 
> > Downloadable assets:
> > disk image: https://storage.googleapis.com/syzbot-assets/f0ef71bdead6/disk-4b946f6b.raw.xz
> > vmlinux: https://storage.googleapis.com/syzbot-assets/0c8251d5df12/vmlinux-4b946f6b.xz
> > kernel image: https://storage.googleapis.com/syzbot-assets/29bad3cdad16/bzImage-4b946f6b.xz
> > 
> > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > Reported-by: syzbot+5cd6299ede4d4f70987b@syzkaller.appspotmail.com
> > 
> > ------------[ cut here ]------------
> > WARNING: CPU: 0 PID: 30386 at net/xfrm/xfrm_state.c:800 __xfrm_state_destroy net/xfrm/xfrm_state.c:800 [inline]
> > WARNING: CPU: 0 PID: 30386 at net/xfrm/xfrm_state.c:800 xfrm_state_put include/net/xfrm.h:928 [inline]
> > WARNING: CPU: 0 PID: 30386 at net/xfrm/xfrm_state.c:800 xfrm_state_migrate+0x13bc/0x1b10 net/xfrm/xfrm_state.c:2165
> 
> Steffen, this looks like we simply forgot to set XFRM_STATE_DEAD
> before the final put() in the error path of xfrm_state_migrate (and
> xfrm_state_clone_and_setup):
> 
> 
> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index 9ea1d45b79e3..7ae10fac7b31 100644
> --- a/net/xfrm/xfrm_state.c
> +++ b/net/xfrm/xfrm_state.c
> @@ -2074,6 +2074,7 @@ static struct xfrm_state *xfrm_state_clone_and_setup(struct xfrm_state *orig,
>  	return x;
>  
>   error:
> +	x->km.state = XFRM_STATE_DEAD;
>  	xfrm_state_put(x);
>  out:
>  	return NULL;
> @@ -2163,6 +2164,7 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
>  
>  	return xc;
>  error:
> +	xc->km.state = XFRM_STATE_DEAD;
>  	xfrm_state_put(xc);
>  	return NULL;
>  }
> 
> 
> Does that look reasonable? The state was never add()/insert()'ed, so
> it goes through put()/destroy() without delete() first that would set
> XFRM_STATE_DEAD.

Right. Looks like this is broken since the migrate API exists.

> It also looks like we're missing a xfrm_dev_state_delete if
> xfrm_state_migrate -> xfrm_state_add fails, since
> xfrm_dev_state_delete gets called during __xfrm_state_delete, and this
> new state will only see xfrm_state_put/__xfrm_state_destroy:
> 
> @@ -2159,10 +2159,13 @@ struct xfrm_state *xfrm_state_migrate(struct xfrm_state *x,
>  		xfrm_state_insert(xc);
>  	} else {
>  		if (xfrm_state_add(xc) < 0)
> -			goto error;
> +			goto error_add;
>  	}
>  
>  	return xc;
> +error_add:
> +	if (xuo)
> +		xfrm_dev_state_delete(xc);

This is correct as well. Thanks for catching these!

  reply	other threads:[~2025-10-15  7:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-05 17:39 [syzbot] [net?] WARNING in xfrm_state_migrate (2) syzbot
2025-10-14 13:26 ` Sabrina Dubroca
2025-10-15  7:43   ` Steffen Klassert [this message]
2025-10-15  9:53     ` Sabrina Dubroca

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=aO9QkNNkZ1JLnnIl@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=syzbot+5cd6299ede4d4f70987b@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /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