]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
netconsole: Fix race condition in between reader and writer of userdata
authorGustavo Luiz Duarte <gustavold@gmail.com>
Tue, 28 Oct 2025 22:06:32 +0000 (15:06 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 30 Oct 2025 00:41:00 +0000 (17:41 -0700)
commit00764aa5c9bbb2044eb04d6d78584a436666b231
tree340b369e8f3a0fd7f337925d1576831ce19cd652
parenta43303809868b22bd1303739ba334e982b234d45
netconsole: Fix race condition in between reader and writer of userdata

The update_userdata() function constructs the complete userdata string
in nt->extradata_complete and updates nt->userdata_length. This data
is then read by write_msg() and write_ext_msg() when sending netconsole
messages. However, update_userdata() was not holding target_list_lock
during this process, allowing concurrent message transmission to read
partially updated userdata.

This race condition could result in netconsole messages containing
incomplete or inconsistent userdata - for example, reading the old
userdata_length with new extradata_complete content, or vice versa,
leading to truncated or corrupted output.

Fix this by acquiring target_list_lock with spin_lock_irqsave() before
updating extradata_complete and userdata_length, and releasing it after
both fields are fully updated. This ensures that readers see a
consistent view of the userdata, preventing corruption during concurrent
access.

The fix aligns with the existing locking pattern used throughout the
netconsole code, where target_list_lock protects access to target
fields including buf[] and msgcounter that are accessed during message
transmission.

Also get rid of the unnecessary variable complete_idx, which makes it
easier to bail out of update_userdata().

Fixes: df03f830d099 ("net: netconsole: cache userdata formatted string in netconsole_target")
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
Link: https://patch.msgid.link/20251028-netconsole-fix-race-v4-1-63560b0ae1a0@meta.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netconsole.c