RE: KASAN: use-after-free Read in rxe_query_port

From: Yanjun Zhu
Date: Tue Mar 10 2020 - 04:21:36 EST


Hi, Leon

Thanks. From the patch https://lore.kernel.org/netdev/20200306134518.84416-1-kgraul@xxxxxxxxxxxxx,

@@ -240,6 +240,9 @@ static void smc_ib_port_event_work(struct work_struct *work)
work, struct smc_ib_device, port_event_work);
u8 port_idx;

+ if (list_empty(&smcibdev->list))
+ return;
+
for_each_set_bit(port_idx, &smcibdev->port_event_mask, SMC_MAX_PORTS) {
smc_ib_remember_port_attr(smcibdev, port_idx + 1);
clear_bit(port_idx, &smcibdev->port_event_mask);

This block is try to check smcibdev->list to avoid ib_query_port after the NIC is down.
But smcibdev->list is used by spinlock when add and del.
"
...
549 spin_lock(&smc_ib_devices.lock);
550 list_add_tail(&smcibdev->list, &smc_ib_devices.list);
551 spin_unlock(&smc_ib_devices.lock);
...

579 spin_lock(&smc_ib_devices.lock);
580 list_del_init(&smcibdev->list); /* remove from smc_ib_devices */
581 spin_unlock(&smc_ib_devices.lock);
...
"
So in the above block, is it necessary to protect smcibdev->list when it is accessed?
Please comment on it.

Thanks a lot.
Zhu Yanjun

-----Original Message-----
From: Leon Romanovsky <leon@xxxxxxxxxx>
Sent: Tuesday, March 10, 2020 3:40 PM
To: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
Cc: syzbot <syzbot+e11efb687f5ab7f01f3d@xxxxxxxxxxxxxxxxxxxxxxxxx>; dledford@xxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; linux-rdma@xxxxxxxxxxxxxxx; Moni Shoua <monis@xxxxxxxxxxxx>; syzkaller-bugs@xxxxxxxxxxxxxxxx; Yanjun Zhu <yanjunz@xxxxxxxxxxxx>
Subject: Re: KASAN: use-after-free Read in rxe_query_port

On Mon, Mar 09, 2020 at 02:34:51PM -0300, Jason Gunthorpe wrote:
> On Sun, Mar 01, 2020 at 03:20:12AM -0800, syzbot wrote:
> > Hello,
> >
> > syzbot found the following crash on:
> >
> > HEAD commit: f8788d86 Linux 5.6-rc3
> > git tree: upstream
> > console output: https://syzkaller.appspot.com/x/log.txt?x=132d3645e00000
> > kernel config: https://syzkaller.appspot.com/x/.config?x=9833e26bab355358
> > dashboard link: https://syzkaller.appspot.com/bug?extid=e11efb687f5ab7f01f3d
> > compiler: gcc (GCC) 9.0.0 20181231 (experimental)
> >
> > Unfortunately, I don't have any reproducer for this crash yet.
> >
> > IMPORTANT: if you fix the bug, please add the following tag to the commit:
> > Reported-by: syzbot+e11efb687f5ab7f01f3d@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> Yanjun, do you have some idea what this could be?

See this fix in the net mailing list.
https://lore.kernel.org/netdev/20200306134518.84416-1-kgraul@xxxxxxxxxxxxx

Thanks

>
> Thanks,
> Jason