Re: [syzbot] KMSAN: uninit-value in p9pdu_readf

From: asmadeus
Date: Sun Oct 10 2021 - 04:37:08 EST


Question for people who know about KMSAN: which of the backtrace or the
'Local variable' message should I trust?

syzbot wrote on Sat, Oct 09, 2021 at 10:48:17PM -0700:
> =====================================================
> BUG: KMSAN: uninit-value in p9pdu_vreadf net/9p/protocol.c:147 [inline]
> BUG: KMSAN: uninit-value in p9pdu_readf+0x46cf/0x4fc0 net/9p/protocol.c:526
> p9pdu_vreadf net/9p/protocol.c:147 [inline]
> p9pdu_readf+0x46cf/0x4fc0 net/9p/protocol.c:526
> p9pdu_vreadf net/9p/protocol.c:198 [inline]
> p9pdu_readf+0x2080/0x4fc0 net/9p/protocol.c:526
> p9_client_stat+0x2b3/0x710 net/9p/client.c:1724
> v9fs_mount+0xc14/0x12c0 fs/9p/vfs_super.c:170

would be 'len' in p9pdu_vreadf, which has to be set as far as I can understand:
> uint16_t len;
>
> errcode = p9pdu_readf(pdu, proto_version,
> "w", &len);
> if (errcode)
> break;
>
> *sptr = kmalloc(len + 1, GFP_NOFS);

with relevant part of p9pdu_readf being:
> case 'w':{
> int16_t *val = va_arg(ap, int16_t *);
> __le16 le_val;
> if (pdu_read(pdu, &le_val, sizeof(le_val))) {
> errcode = -EFAULT;
> break;
> }
> *val = le16_to_cpu(le_val);
> }
> ...
> return errcode;

e.g. either len or errcode should be set...

But:
> Local variable ----ecode@p9_check_errors created at:
> p9_check_errors+0x68/0xb90 net/9p/client.c:506
> p9_client_rpc+0xd90/0x1410 net/9p/client.c:801

is something totally different, p9_client_rpc happens before the
p9pdu_readf call in p9_client_stat, and ecode is local to
p9_check_errors, I don't see how it could get that far.

Note that inspecting p9_check_errors manually, there is a case where
ecode is returned (indirectly through err = -ecode) without being
initialized, so I will send a patch for that at least, but I have no
idea if that is what has been reported and it should be trivial to
reproduce so I do not see why syzbot does not have a reproducer -- it
retries running the last program that triggered the error before sending
the report, right?

--
Dominique Martinet | Asmadeus