net/core/sock_copy.c:274 sock_copy_run() error: buffer overflow 'sock_copy_queues' 64 <= u32max
kernel test robot
build botUnfiltered warning: this smatch report is sent as-is and has not been reviewed for false positives, so please treat it with due skepticism.
BCC: [email protected]
CC: [email protected]
TO: Kumar Kartikeya Dwivedi <[email protected]>
tree: https://github.com/kkdwivedi/linux sock-copy head: bc98958cae1e859b7deaa9d24e1dfee59760b9e7 commit: b99a63ee7b6d5203ce14049aede8bd21d03a0735 [53/57] net: Split the copy of a socket's send over BPF kthreads
:::::: branch date: 9 hours ago
:::::: commit date: 9 hours ago
config: xtensa-randconfig-2200-20261129 (https://download.01.org/0day-ci/archive/20261129/[email protected]/config)
compiler: xtensa-linux-gcc (GCC) 16.2.0
smatch: v0.5.0-9187-g5189e3fb
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
New smatch warnings:net/core/sock_copy.c:274 sock_copy_run() error: buffer overflow 'sock_copy_queues' 64 <= u32max net/core/sock_copy.c:274 sock_copy_run() error: buffer overflow 'sock_copy_queues' 64 <= u32max net/core/sock_copy.c:274 sock_copy_run() error: buffer overflow 'sock_copy_queues' 64 <= u32max
Old smatch warnings:arch/xtensa/include/asm/thread_info.h:97 current_thread_info() warn: inconsistent indenting
vim +/sock_copy_queues +274 net/core/sock_copy.c
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 256
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 257 /**
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 258 * sock_copy_run() - copy what the send has planned and not copied
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 259 * @copy: the send's copy
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 260 *
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 261 * The bytes are cut into pieces of at least SOCK_COPY_PIECE_MIN, one the
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 262 * caller's and one for each of the socket's queues that has a thread. Returns
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 263 * once all are copied.
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 264 */
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 265 void sock_copy_run(struct sock_copy *copy)
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 266 {
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 267 size_t total = copy->planned - copy->done, each, off;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 268 unsigned int pieces = 1, i;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 269 u64 since;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 270
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 271 if (!total)
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 272 return;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 273 for (i = 0; i < copy->nr && pieces <= SOCK_COPY_MAX; i++)
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 @274 if (rcu_access_pointer(sock_copy_queues[copy->first + i].thread))
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 275 copy->piece[pieces++].queue = copy->first + i;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 276 pieces = clamp_t(unsigned int, total / SOCK_COPY_PIECE_MIN, 1, pieces);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 277 each = round_up(DIV_ROUND_UP(total, pieces), L1_CACHE_BYTES);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 278
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 279 atomic_set(©->pending, 0);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 280 for (i = 1, off = copy->done + each; i < pieces && off < copy->planned; i++, off += each) {
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 281 struct sock_copy_piece *piece = ©->piece[i];
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 282
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 283 piece->copy = copy;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 284 piece->off = off;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 285 piece->len = min(each, copy->planned - off);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 286 INIT_LIST_HEAD(&piece->node);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 287 atomic_inc(©->pending);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 288 if (!sock_copy_queue_piece(piece)) {
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 289 atomic_dec(©->pending);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 290 sock_copy_piece_run(piece);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 291 }
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 292 }
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 293 pieces = i;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 294
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 295 copy->piece[0].copy = copy;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 296 copy->piece[0].off = copy->done;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 297 copy->piece[0].len = min(each, total);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 298 sock_copy_piece_run(©->piece[0]);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 299
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 300 /* Pairs with the release in sock_copy_poll(): a piece done is copied. */
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 301 since = local_clock();
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 302 while (atomic_read_acquire(©->pending)) {
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 303 if (local_clock() - since > SOCK_COPY_TAKE_NS) {
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 304 for (i = 1; i < pieces; i++) {
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 305 if (sock_copy_take(©->piece[i])) {
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 306 sock_copy_piece_run(©->piece[i]);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 307 atomic_dec(©->pending);
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 308 }
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 309 }
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 310 /* What is left runs on a thread, which may be preempted. */
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 311 cond_resched();
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 312 since = local_clock();
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 313 }
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 314 cpu_relax();
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 315 }
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 316 copy->done = copy->planned;
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 317 }
b99a63ee7b6d52 Kumar Kartikeya Dwivedi 2026-11-28 318 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki