[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <07e71db1-d6ea-4cb6-8342-86da3c11773e@mev.co.uk>
Date: Mon, 20 Oct 2025 18:29:14 +0100
From: Ian Abbott <abbotti@....co.uk>
To: Жандарович Никита Игоревич <n.zhandarovich@...tech.ru>,
"syzbot+af53dea94b16396bc646@...kaller.appspotmail.com"
<syzbot+af53dea94b16396bc646@...kaller.appspotmail.com>,
H Hartley Sweeten <hsweeten@...ionengravers.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"lvc-project@...uxtesting.org" <lvc-project@...uxtesting.org>
Subject: Re: [syzbot] [kernel?] divide error in comedi_inc_scan_progress
On 20/10/2025 14:36, Жандарович Никита Игоревич wrote:
> Hi Ian,
>
> Thank you for your response!
>
>>> ...
>>> if (!(s->subdev_flags & SDF_PACKED) && (cmd->chanlist_len != 0)) {
>>> async->cur_chan += comedi_bytes_to_samples(s, num_bytes);
>>> async->cur_chan %= cmd->chanlist_len;
>>> }
>>> ...
>>>
>>> Any suggestions are greatly appreciated!
>>
>> I have a plan to deal with these unexpected interrupts, at least within the
>> Comedi core functions. The basic idea would be to for the Comedi core
>> functions called by the ISRs to check that the subdevice is in the running state
>> and increment a reference counter (either a refcount_t or a struct kref) if it is
>> safe to proceed. Then it will be allowed to assume that the struct
>> comedi_async contents are reasonable until it decrements the reference
>> counter. Some other task may be calling
>> do_become_nonbusy() in parallel with the above. After
>> do_become_nonbusy() clears the COMEDI_SRF_RUNNING flag to mark the
>> subdevice as not being in the running state, it should wait until it is safe to
>> continue before calling comedi_buf_reset(). This will make use of the
>> reference counter and a struct completion. The reference counter and struct
>> completion can be stored as members of struct comedi_async.
>>
>> There may be other parts of individual driver ISRs that use struct
>> comedi_async directly and may need changing to do similar checks. The
>> checking and final decrement can done by a couple of new exported
>> functions:
>>
>> bool comedi_get_is_subdevice_running(struct comedi_subdevice *s); void
>> comedi_put_is_subdevice_running(struct comedi_subdevice *s);
>>
>> If comedi_get_is_subdevice_running(s) returns true, the ISR can safely
>> access s->async and then should call comedi_put_is_subdevice_running(s)
>> when it has finished.
>>
>>
>
> I'll try to tackle this idea when I get the chance, thanks for your suggestion!
I'm trying to implement it at the moment.
--
-=( Ian Abbott <abbotti@....co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
Powered by blists - more mailing lists