Re: [PATCH] scsi: pm8001: Fix potential TOCTOU race in pm8001_find_tag

From: James Bottomley

Date: Mon Jan 19 2026 - 22:42:51 EST


On Tue, 2026-01-20 at 00:50 +0800, Chengfeng Ye wrote:
> > I don't get how a race is possible here.  Before the query function
> > begins, the sas logic calls abort task on the tag, which means the
> > controller should ensure there are no further completion functions
> > for
> > it regardless of whether the abort succeeds or not.
>
> Thanks a lot for looking into it!
>
> Sorry that I might miss something as I am not very familiar with the
> code. But I also notice the find_tag() function is also invoked
> inside the abort function (and invoked before the completion).

This is part of the problem, though: you're apparently using some tool
looking for data races in an ancient driver but most of what you find
isn't significant and costs us review cycles to check.

> For the find_tag() invoked inside the abort path will it be a race?
> https://github.com/torvalds/linux/blob/master/drivers/scsi/pm8001/pm8001_sas.c#L1085

So the theory now is that in the couple of instruction cycles between
checking lldd_task and dereferencing it to find the tag, it goes null?
That's so astronomically unlikely precisely because abort is only
called on a task that timed out anyway and the completion function sets
the state done flags, which sas error handling checks, long before it
begins to free the lldd_task.

Regards,

James