net: hamradio: 6pack: fix uninit-value in sixpack_receive_buf
Subsystems (3)
PATCH 1/1 net: hamradio: 6pack: fix uninit-value in sixpack_receive_buf
sixpack_receive_buf() does not properly skip bytes with TTY error flags. The while loop iterates through the flags buffer but never advances the data pointer (cp), and passes the original count including error bytes to sixpack_decode(). This causes sixpack_decode() to process bytes that should have been skipped due to TTY errors.
Fix this by processing bytes one at a time, advancing cp on each iteration, and only passing non-error bytes to sixpack_decode(). This matches the pattern used by slip_receive_buf() and mkiss_receive_buf() for the same purpose.
--- drivers/net/hamradio/6pack.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/hamradio/6pack.c +4 -5
@@ -391,7 +391,6 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t count) {struct sixpack *sp; -size_t count1;if (!count)return ;
@@ -401,16 +400,16 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp,return ;/* Read the characters out of the buffer */ - count1 = count; -while (count) { - count--; +while (count--) {if (fp && *fp++) {if (!test_and_set_bit (SIXPF_ERROR , &sp->flags)) sp->dev->stats.rx_errors++; + cp++;continue ; } +sixpack_decode (sp, cp,1 ); + cp++; } -sixpack_decode (sp, cp, count1);tty_unthrottle (tty); }
Signature · 1 line
2.53.0
Simon Horman
reviewerQuoted 23 lines · Mashiro Chen
sixpack_receive_buf()does not properly skip bytes with TTY error flags. The while loop iterates through the flags buffer but never advances the data pointer (cp), and passes the original count including error bytes tosixpack_decode(). This causessixpack_decode()to process bytes that should have been skipped due to TTY errors.Fix this by processing bytes one at a time, advancing cp on each iteration, and only passing non-error bytes to
sixpack_decode(). This matches the pattern used byslip_receive_buf()andmkiss_receive_buf()for the same purpose.Reported-by [email protected]Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Mashiro Chen <[email protected]>--- drivers/net/hamradio/6pack.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/net/hamradio/6pack.c +0
-0
...
Quoted 11 lines
drivers/net/hamradio/6pack.c +1
-3@@ -401,16 +400,16 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp,return ;/* Read the characters out of the buffer */ - count1 = count; -while (count) { - count--; +while (count--) {if (fp && *fp++) {if (!test_and_set_bit (SIXPF_ERROR , &sp->flags)) sp->dev->stats.rx_errors++;
drivers/net/hamradio/6pack.c static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp, · line 415
Quoted 10 lines
drivers/net/hamradio/6pack.c +3
-1+ cp++;continue ; } +sixpack_decode (sp, cp,1 ); + cp++; } -sixpack_decode (sp, cp, count1);tty_unthrottle (tty); }
Hi,
I am wondering if this could be expressed more succinctly by placing the cp++ in a common branch of execution.
Something like this (completely untested!)
@@ -401,16 +400,15 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp,
return;
/* Read the characters out of the buffer */
- count1 = count;
- while (count) {
- count--;
+ while (count--) {
if (fp && *fp++) {
if (!test_and_set_bit(SIXPF_ERROR, &sp->flags))
sp->dev->stats.rx_errors++;
- continue;
+ } else {
+ sixpack_decode(sp, cp, 1);
}
+ cp++;
}
- sixpack_decode(sp, cp, count1);
tty_unthrottle(tty);
}
Also, while I don't think it is appropriate to be included in a fix. As a follow-up sixpack_decode() could be simplified by removing the count parameter, which is now always passed the value 1.
PATCH v2 1/1 net: hamradio: 6pack: fix uninit-value in sixpack_receive_buf
sixpack_receive_buf() does not properly skip bytes with TTY error flags. The while loop iterates through the flags buffer but never advances the data pointer (cp), and passes the original count including error bytes to sixpack_decode(). This causes sixpack_decode() to process bytes that should have been skipped due to TTY errors.
Fix this by processing bytes one at a time, advancing cp on each iteration, and only passing non-error bytes to sixpack_decode(). This matches the pattern used by slip_receive_buf() and mkiss_receive_buf() for the same purpose.
--- drivers/net/hamradio/6pack.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/hamradio/6pack.c +4 -6
@@ -391,7 +391,6 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t count) {struct sixpack *sp; -size_t count1;if (!count)return ;
@@ -401,16 +400,15 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp,return ;/* Read the characters out of the buffer */ - count1 = count; -while (count) { - count--; +while (count--) {if (fp && *fp++) {if (!test_and_set_bit (SIXPF_ERROR , &sp->flags)) sp->dev->stats.rx_errors++; -continue ; + }else { +sixpack_decode (sp, cp,1 ); } + cp++; } -sixpack_decode (sp, cp, count1);tty_unthrottle (tty); }
Signature · 1 line
2.53.0
Simon Horman
reviewerQuoted 11 lines · Mashiro Chen
sixpack_receive_buf()does not properly skip bytes with TTY error flags. The while loop iterates through the flags buffer but never advances the data pointer (cp), and passes the original count including error bytes tosixpack_decode(). This causessixpack_decode()to process bytes that should have been skipped due to TTY errors.Fix this by processing bytes one at a time, advancing cp on each iteration, and only passing non-error bytes to
sixpack_decode(). This matches the pattern used byslip_receive_buf()andmkiss_receive_buf()for the same purpose.
Quoted 4 lines
Reported-by [email protected]Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Suggested-by Simon Horman <[email protected]>
FWIIW, I don't think my suggested by tag is strictly necessary here:
I just suggested a minor tweak, not the idea the patch implements
Quoted 1 line
Signed-off-by Mashiro Chen <[email protected]>
Sorry for not noticing this earlier, but AI generated review flags that while this change looks correct, it's not clear how it relates to the sysbot report: IOW, how is it that bytes with TTY error flags may be uninitialized?
...
Quoted 4 lines · Simon Horman
Sorry for not noticing this earlier, but AI generated review flags that while this change looks correct, it's not clear how it relates to the sysbot report: IOW, how is it that bytes with TTY error flags may be uninitialized?
Thanks for the question, and for the earlier review.
The TTY receive_buf() contract is that for positions where fp[i] != 0 (error flag set), the caller must discard cp[i] -- the TTY driver does not guarantee a meaningful value there. In syzbot's fuzzing harness (pty/ldisc injection), the fuzzer allocates a tty_buffer, sets error flags on certain byte positions, but leaves the corresponding entries in the char buffer uninitialized. KMSAN then detects that sixpack_decode() reads those uninitialized bytes.
slip_receive_buf() and mkiss_receive_buf() already handle this correctly by advancing their char pointer past error-flagged bytes before calling their decode functions. sixpack_receive_buf() had the same structure but cp was never advanced, so the full original buffer -- including the uninit error-flagged positions -- was forwarded to sixpack_decode().
I have also dropped the Suggested-by tag per your note, and submitted a v2 with the commit message expanded to explain the uninit-value connection more clearly.
Thanks,
Mashiro Chen
PATCH v2 1/1 net: hamradio: 6pack: fix uninit-value in sixpack_receive_buf
In reply to Simon Hormansixpack_receive_buf() does not properly skip bytes with TTY error flags. The while loop iterates through the flags buffer but never advances the data pointer (cp), and passes the original count (including error bytes) to sixpack_decode(). This causes sixpack_decode() to process bytes that should have been skipped due to TTY errors. The TTY layer does not guarantee that cp[i] holds a meaningful value when fp[i] is set, so passing those positions to sixpack_decode() results in KMSAN reporting an uninit-value read.
Fix this by processing bytes one at a time, advancing cp on each iteration, and only passing valid (non-error) bytes to sixpack_decode(). This matches the pattern used by slip_receive_buf() and mkiss_receive_buf() for the same purpose.
--- drivers/net/hamradio/6pack.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/hamradio/6pack.c +4 -5
@@ -391,7 +391,6 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t count) {struct sixpack *sp; -size_t count1;if (!count)return ;
@@ -401,16 +400,16 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp,return ;/* Read the characters out of the buffer */ - count1 = count; -while (count) { - count--; +while (count--) {if (fp && *fp++) {if (!test_and_set_bit (SIXPF_ERROR , &sp->flags)) sp->dev->stats.rx_errors++; + cp++;continue ; } +sixpack_decode (sp, cp,1 ); + cp++; } -sixpack_decode (sp, cp, count1);tty_unthrottle (tty); }
Signature · 1 line
2.53.0
Quoted 14 lines · Mashiro Chen
sixpack_receive_buf()does not properly skip bytes with TTY error flags. The while loop iterates through the flags buffer but never advances the data pointer (cp), and passes the original count (including error bytes) tosixpack_decode(). This causessixpack_decode()to process bytes that should have been skipped due to TTY errors. The TTY layer does not guarantee that cp[i] holds a meaningful value when fp[i] is set, so passing those positions tosixpack_decode()results in KMSAN reporting an uninit-value read.Fix this by processing bytes one at a time, advancing cp on each iteration, and only passing valid (non-error) bytes to
sixpack_decode(). This matches the pattern used byslip_receive_buf()andmkiss_receive_buf()for the same purpose.
Quoted 4 lines
Reported-by [email protected]Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Mashiro Chen <[email protected]>
Thanks for the updates.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 8 Apr 2026 01:31:01 +0800 you wrote:
sixpack_receive_buf()does not properly skip bytes with TTY error flags. The while loop iterates through the flags buffer but never advances the data pointer (cp), and passes the original count (including error bytes) tosixpack_decode(). This causessixpack_decode()to process bytes that should have been skipped due to TTY errors. The TTY layer does not guarantee that cp[i] holds a meaningful value when fp[i] is set, so passing those positions tosixpack_decode()results in KMSAN reporting an uninit-value read.[...]
Here is the summary with links:
- [v2] net: hamradio: 6pack: fix uninit-value in sixpack_receive_buf
https://git.kernel.org/netdev/net/c/bf9a38803b26
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Simon Horman
reviewerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: hamradio: 6pack: fix uninit-value in sixpack_receive_buf
This commit fixes sixpack_receive_buf() to properly skip bytes with TTY error flags by processing bytes one at a time and only passing non-error bytes to sixpack_decode(). This matches the pattern used in slip_receive_buf() and mkiss_receive_buf().
Quoted 22 lines
drivers/net/hamradio/6pack.c +1
-4@@ -391,7 +391,6 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t count) {struct sixpack *sp; -size_t count1;if (!count)return ;@@ -401,16 +400,16 @@ static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp,return ;/* Read the characters out of the buffer */ - count1 = count; -while (count) { - count--; +while (count--) {if (fp && *fp++) {if (!test_and_set_bit (SIXPF_ERROR , &sp->flags)) sp->dev->stats.rx_errors++;
drivers/net/hamradio/6pack.c static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp, · line 415
Quoted 10 lines
drivers/net/hamradio/6pack.c +3
-1+ cp++;continue ; } +sixpack_decode (sp, cp,1 ); + cp++; } -sixpack_decode (sp, cp, count1);tty_unthrottle (tty); }
The commit title states this fixes "uninit-value in sixpack_receive_buf", but is this the exact cause of the KMSAN report?
The syzbot report confirms KMSAN detected uninit-value in sixpack_decode when reading pre_rbuff[count1]. The uninit memory originated from tty_buffer_alloc via kmalloc_flex (GFP_ATOMIC | __GFP_NOWARN, not zeroed).
However, bytes in the tty buffer should be initialized after being written by serial8250_read_char -> uart_insert_char -> tty_insert_flip_char, which writes both the character (from inb() I/O port read) and the flag. KMSAN's __msan_instrument_asm_store() should unpoison inline asm outputs including inb results.
The code fix addresses a genuine logic error where error-flagged bytes were not skipped (claims 1-5 are verified true). But the connection between this bug and the specific KMSAN uninit-value report is unclear, since the tty bytes should be initialized after UART driver processing.
Could the KMSAN trigger involve subtle shadow tracking through tty buffer allocation and inline asm instrumentation rather than the described code bug? The syzbot report notes "Unfortunately, I don't have any reproducer for this issue yet," which makes verification difficult.
The fix is correct regardless - it matches the established pattern in slip_receive_buf() and mkiss_receive_buf() for handling error-flagged bytes. Should the commit title more accurately describe what the fix addresses?