Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp859092rdd; Wed, 10 Jan 2024 01:23:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLvoQQvsGpfHgBET13DbnrnArwVoEOg0RG/gf360edBeh5wcVoBWCXJke8TKy4G59rWHXj X-Received: by 2002:a19:9145:0:b0:50e:4eb9:33b4 with SMTP id y5-20020a199145000000b0050e4eb933b4mr263913lfj.4.1704878631275; Wed, 10 Jan 2024 01:23:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704878631; cv=none; d=google.com; s=arc-20160816; b=dqxrC3K/W3junCEFgtrwh4lFSRX2JcyPZvLeUmH8u6/BmNg92JUJer4JNMTaX1X8aM W18fpy2BOywW1+xN3oIxf9baw5b641qkK2Cpq6sZAM6/iDubt4Ed9nytNhmxZS07JvSQ NQ03OCHIgsUuxPjUFwaHMLy0Z627trw64gf+J5vWBcwW/FQqZw+KNyRxwTCEJwX2OJb0 OuVMUlE8Z1TnnnAxb9V7WSxrcmUGLHhyryjlr7uUjNWpg1997Wt2xZXepOszyEUTVIPc q2U78tYb/DtOW2pSRom8ZnZMDclIW7yWQ29ntp56ydOKfKNDmpqyrSpMGz8Sm3dznJEQ w+Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-filter; bh=fnpR3T7RIMq+i4kpDaWxriwBNNBqwi1jzsXS3sBDB88=; fh=ei7ex01sMEp5aguKT+ISAmc6GIgCPB8Mv7XtzJ4aq74=; b=sSwXH2XIScnlIXi5d3FO4823kkZE/O4Ll2TI4equB41P/Q+mM0Yr5X83/YHpAcCvrM fZg+e45YWG06ke0+K4jc4net0E/O3yx1IzIlQdTCWU4+gNR7lKanb3+OhC+b0gVmOsrm Wpb3s6XNeeu7EmrB/ZTBjtyDg3WCXI/2vRcWzJrVGE+L6Y4yP2oiXKxkcLaTAE/wSSDx tdYUOrMTYXEIt7DPJJby5PlJyPao8797RmerMFnQjKeST9J5WfGrt8gVsf5tL5MjGioD uyKbmKpdhDaJ95KEcGiegp90IYflsMzQxD0X88bczwgPJbHnaUyFbEfhX8oVDgPCSg7G B86Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b="l5z728/b"; spf=pass (google.com: domain of linux-kernel+bounces-21897-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21897-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p17-20020a17090635d100b00a26f5e38a09si1626246ejb.892.2024.01.10.01.23.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 01:23:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21897-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b="l5z728/b"; spf=pass (google.com: domain of linux-kernel+bounces-21897-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21897-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 07BF31F257B3 for ; Wed, 10 Jan 2024 09:23:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2110E3E49D; Wed, 10 Jan 2024 09:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="l5z728/b" Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67020210B; Wed, 10 Jan 2024 09:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Received: from localhost (unknown [46.242.8.170]) by mail.ispras.ru (Postfix) with ESMTPSA id 51F7740F1DF6; Wed, 10 Jan 2024 09:23:30 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 51F7740F1DF6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1704878610; bh=fnpR3T7RIMq+i4kpDaWxriwBNNBqwi1jzsXS3sBDB88=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=l5z728/bshdC1sRpZN1hz4gEfTbYS7CO8lJ873fFixp9AMKe7b72BtugFEPL36z9j A66zPVLlEeEqdi2cfWVXm0QUZFojFg5OkdXVvvG1sajPNfpn+JPYlZzMiNylB3JGiv eAbqv1A1QN15kY159O/C16PKpVk3pacaFS5fsfgc= Date: Wed, 10 Jan 2024 12:23:30 +0300 From: Fedor Pchelkin To: Tali Perry Cc: Rand Deeb , lvc-project@linuxtesting.org, voskresenski.stanislav@confident.ru, Benjamin Fair , Avi Fishman , Patrick Venture , openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Nancy Yuen , linux-i2c@vger.kernel.org, deeb.rand@confident.ru, Tomer Maimon Subject: Re: Re: [lvc-project] [PATCH] i2c: Fix NULL pointer dereference in npcm_i2c_reg_slave Message-ID: <111837c6-6c60-4bd4-9e66-1c652a43f3ae-pchelkin@ispras.ru> References: <20240109145121.8850-1-rand.sec96@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On 24/01/10 10:43AM, Tali Perry wrote: > On Tue, Jan 9, 2024 at 4:52 PM Rand Deeb wrote: > > > > In the npcm_i2c_reg_slave function, a potential NULL pointer dereference > > issue occurs when 'client' is NULL. This patch adds a proper NULL check for > > 'client' at the beginning of the function to prevent undefined behavior. > > > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > > > Signed-off-by: Rand Deeb > > --- > > drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++---- > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c > > index c1b679737240..cfabfb50211d 100644 > > --- a/drivers/i2c/busses/i2c-npcm7xx.c > > +++ b/drivers/i2c/busses/i2c-npcm7xx.c > > @@ -1243,13 +1243,14 @@ static irqreturn_t npcm_i2c_int_slave_handler(struct npcm_i2c *bus) > > static int npcm_i2c_reg_slave(struct i2c_client *client) > > { > > unsigned long lock_flags; > > - struct npcm_i2c *bus = i2c_get_adapdata(client->adapter); > > - > > - bus->slave = client; > > + struct npcm_i2c *bus; > > > > - if (!bus->slave) > > + if (!client) > > return -EINVAL; > > > > + bus = i2c_get_adapdata(client->adapter); > > + bus->slave = client; > > + > > if (client->flags & I2C_CLIENT_TEN) > > return -EAFNOSUPPORT; > > > > -- > > 2.34.1 > > > > > Thanks for the patch! > > Reviewed-by:tali.perry1@gmail.com If I'm not missing something, npcm_i2c_reg_slave() is called via a function pointer ->reg_slave here [1]. And seems `client` can't be NULL there. Other drivers implementing ->reg_slave function don't check its argument. Maybe we should just drop `if (!bus->slave)` check? [1]: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-slave.c#L48