From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp105.iad3b.emailsrvr.com (smtp105.iad3b.emailsrvr.com [146.20.161.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA23333065C for ; Mon, 26 Jan 2026 13:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=146.20.161.105 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769433723; cv=none; b=aorgYOhy0p2Ge/gA1DpWGT/EycBDFCvLk1/rDOf1rirLTSnEzyrJD0gm87ItFPSM1BuURCKF5EbfGYJsIkzacSSktYmCxmx0Yy+YC0dZsbIsRbDadm3zBeTLO/wi96myOXB/OZTEQINNgR2yTHtpoVHN9tWgsXC6NBDhX9hLWH8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769433723; c=relaxed/simple; bh=pqwWuf32iufvqb1Hj/ERtzdsnC0cfoN8V2zQ+AX0Y1k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KbnkTAsh8Ee9Dg4WPSYs8xovdvd9KZiocfTTQwZDBWqk/SGv12EvtmeURgmQbzv3xKN4CbvlmwSEjoaHF1hzGIZWHaLBt5l3cZaYsLdZUSWcy3wEZBY7wXsqdXOljqsUnjuCelbhz6q/j3jyHrPItnF6+zN8dLu0+D8MySO78iA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mev.co.uk; spf=pass smtp.mailfrom=mev.co.uk; dkim=pass (1024-bit key) header.d=g001.emailsrvr.com header.i=@g001.emailsrvr.com header.b=JXWfIOTF; dkim=pass (1024-bit key) header.d=mev.co.uk header.i=@mev.co.uk header.b=XPWqw7IM; arc=none smtp.client-ip=146.20.161.105 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mev.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mev.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=g001.emailsrvr.com header.i=@g001.emailsrvr.com header.b="JXWfIOTF"; dkim=pass (1024-bit key) header.d=mev.co.uk header.i=@mev.co.uk header.b="XPWqw7IM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=g001.emailsrvr.com; s=feedback; t=1769432654; bh=pqwWuf32iufvqb1Hj/ERtzdsnC0cfoN8V2zQ+AX0Y1k=; h=Date:Subject:To:From:From; b=JXWfIOTFhqxOjaSCky6e2zpk6bD3WPke6B66EAK7ncXzD+cH6DqmGmsHJ9OG3RW75 8f1oQVJxNlwsg8kDaDqbDq26Wnzfmb5cnqn0xD+H4FpdRgBAk8iCEXNZlDKKoR4/mw 86wJwlxdcrkq0j544S+Cx5QJ9KJfqlLd3aeId/kM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1769432654; bh=pqwWuf32iufvqb1Hj/ERtzdsnC0cfoN8V2zQ+AX0Y1k=; h=Date:Subject:To:From:From; b=XPWqw7IMsapyn8NMp7smQydVvUjYN7yxLgtwqTHCGxtJ15lmlgNzERU7AvZVFiyj5 r2dEJVT6JGlObroxnGt9Bo10DIkAzM256wPGWt2jRw3tAkIDYdaFRgPv10T2l+VZyr A/4RNeGBxM5mDjjS+crA4Dlnul0qqIOKF8SfjhPg= X-Auth-ID: abbotti@mev.co.uk Received: by smtp6.relay.iad3b.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id 9F026202EF; Mon, 26 Jan 2026 08:04:13 -0500 (EST) Message-ID: Date: Mon, 26 Jan 2026 13:04:12 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] comedi: dt2815: add hardware detection to prevent crash To: Deepanshu Kartikey , hsweeten@visionengravers.com Cc: linux-kernel@vger.kernel.org, syzbot+72f94b474d6e50b71ffc@syzkaller.appspotmail.com References: <20260126070458.10974-1-kartikey406@gmail.com> Content-Language: en-GB From: Ian Abbott Organization: MEV Ltd. In-Reply-To: <20260126070458.10974-1-kartikey406@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Classification-ID: 3f9f6686-8176-4097-81ea-bdd38444de0e-1-1 On 26/01/2026 07:04, Deepanshu Kartikey wrote: > The dt2815 driver crashes when attached to I/O ports without actual > hardware present. This occurs because syzkaller or users can attach > the driver to arbitrary I/O addresses via COMEDI_DEVCONFIG ioctl. > > When no hardware exists at the specified port, inb() operations return > 0xff (floating bus), but outb() operations can trigger page faults due > to undefined behavior, especially under race conditions: > > BUG: unable to handle page fault for address: 000000007fffff90 > #PF: supervisor write access in kernel mode > #PF: error_code(0x0002) - not-present page > RIP: 0010:dt2815_attach+0x6e0/0x1110 > > Add hardware detection by reading the status register before attempting > any write operations. If the read returns 0xff, assume no hardware is > present and fail the attach with -ENODEV. This prevents crashes from > outb() operations on non-existent hardware. > > Reported-by: syzbot+72f94b474d6e50b71ffc@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=72f94b474d6e50b71ffc > Tested-by: syzbot+72f94b474d6e50b71ffc@syzkaller.appspotmail.com > Signed-off-by: Deepanshu Kartikey > --- > drivers/comedi/drivers/dt2815.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/comedi/drivers/dt2815.c b/drivers/comedi/drivers/dt2815.c > index 03ba2fd18a21..7c642860f127 100644 > --- a/drivers/comedi/drivers/dt2815.c > +++ b/drivers/comedi/drivers/dt2815.c > @@ -175,6 +175,18 @@ static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it) > ? current_range_type : voltage_range_type; > } > > + /* > + * Check if hardware is present before attempting any I/O operations. > + * Reading 0xff from status register typically indicates no hardware > + * on the bus (floating bus reads as all 1s). > + */ > + if (inb(dev->iobase + DT2815_STATUS) == 0xff) { > + dev_err(dev->class_dev, > + "No hardware detected at I/O base 0x%lx\n", > + dev->iobase); > + return -ENODEV; > + } > + > /* Init the 2815 */ > outb(0x00, dev->iobase + DT2815_STATUS); > for (i = 0; i < 100; i++) { Thanks. Looks good with some reservations. It's probably fine for this device (assuming the status register cannot legitimately read back 0xff before the board has been initialized), but the same technique might not work for other devices (for example 8255, which has 4 registers, 3 of which can legitimately read 0xff, and the other being a write-only register). In general, we assume the device is being configured correctly as configuration requires CAP_SYSADMIN privileges. I think I will start adding some base address sanity checks to the drivers. For example, The DT2815 hardware jumpers to configure the base address base addresses in the range 0x200 to 0x3FE aligned on 2-byte boundaries. Reviewed-by: Ian Abbott -- -=( Ian Abbott || 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 )=-