mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] net: fix token index wraparound in SO_DEVMEM_DONTNEED
@ 2026-11-10 12:03 Xia Yan
  2026-11-11 22:16 ` Stanislav Fomichev
  0 siblings, 1 reply; 2+ messages in thread
From: Xia Yan @ 2026-11-10 12:03 UTC (permalink / raw)
  To: netdev
  Cc: edumazet, kuniyu, pabeni, willemb, davem, kuba, horms,
	asml.silence, kaiyuanz, linux-kernel, almasrymina, yana06070

SO_DEVMEM_DONTNEED computes each index as token_start + j, in 32-bit
unsigned arithmetic. A start of 0xfffffffe and a count of 4 produce
indices 0xfffffffe, 0xffffffff, 0 and 1. Once the sum wraps, the loop
can erase an existing low-numbered token from the same socket.

Skip an index when the sum wraps below token_start. The check runs
after the MAX_DONTNEED_FRAGS test; skipped indices still consume the
1024-item budget. Tokens allocated with xa_limit_31b are unaffected.

Found during a code review of the devmem token release path.

Built net/core/sock.o for i386 and x86_64 with W=1.

A temporary UML module tested copies of both loops against a real
XArray. All five cases passed. The wrapping case deleted one entry
with the original loop and none with the guard.

Fixes: 678f6e28b5f6 ("net: add SO_DEVMEM_DONTNEED setsockopt to release RX frags")
Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
---
 net/core/sock.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/sock.c b/net/core/sock.c
index e2401d7..90f59b9 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1115,6 +1115,8 @@ sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen)
 		for (j = 0; j < tokens[i].token_count; j++) {
 			if (++num_frags > MAX_DONTNEED_FRAGS)
 				goto frag_limit_reached;
+			if (tokens[i].token_start + j < tokens[i].token_start)
+				continue;
 
 			netmem_ref netmem = (__force netmem_ref)__xa_erase(
 				&sk->sk_user_frags, tokens[i].token_start + j);



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-11 22:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 12:03 [PATCH net-next] net: fix token index wraparound in SO_DEVMEM_DONTNEED Xia Yan
2026-11-11 22:16 ` Stanislav Fomichev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®