Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3601054pxb; Mon, 24 Jan 2022 13:14:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzckypgHnD252EWTNEwwe9oZ4lGOz13FZuEq12Ag9R49ngsLirz2LuwbuMVbCdu/U1Dn5Jg X-Received: by 2002:a17:902:d2cb:b0:14b:6611:4c6b with SMTP id n11-20020a170902d2cb00b0014b66114c6bmr2730205plc.7.1643058874847; Mon, 24 Jan 2022 13:14:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058874; cv=none; d=google.com; s=arc-20160816; b=njGgux9/sNaYERGlS416H9+LzGPG1bA9HUYJR1FoGIJqhs+E38IgMYGDnb9HRftMXs jJkLFDUR+7TMyq5HcgXpBPnAIrKIMQH1KN+SOFMHKLjk3Z9dmlzOysnN5Z1oMjzFcp2Y kI+akTs1MMvPoNuH0Zk8UavinMI0eZbqYmWGkC4r7BnIuDrnOVWWc4jnM6ypJcPwQl8W 83q1fp22xVUqAFsa0YrDupNKt1orJQENTSWGQxPjWBv0rKeL/14A90fW58g5XBl0wqmW mV0HEq/rZVd9buAbR6vM6c7tdAu0nWmbu3QrezgqwDGdnnCHrDh++s44fRJYctyITE8/ wq1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=idp0EhV3dbkl0oD1YpRy70NQQhH+tncvdGzamHpYgkk=; b=NfIQE4Z4QqY97FZ5VbY5dfUkqoTnkuivxolkjX3nxyPQquXsw6HAlAQT0lRJYB9Xc2 nuLAeQkCm5KTtCB82fnNLdWzvjFIHjt0o0z4afwsPh6ow2Hwj6366G6JAkPyVCGX8lNv FFp/R475Qodn0fnvfsC0Ok70fxcfI/A/luKHrosGqZcoEGmIYfnFyY97+kwf2tbeVBY7 CVyY+iNedzCsOr/R4i5OMD88HiLD5nvdLvJfxLn/4jrLradTkVBeqqlMISqM/9oJoPN4 aKJKXumY8GtXnuUcJr2dEhwHFTYgU2TRpDnvl19YE/iYA/dUbK0p7bm06m0kSKCEE2DI u1VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mIm69H7C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t2si15492886plg.360.2022.01.24.13.14.19; Mon, 24 Jan 2022 13:14:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mIm69H7C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359049AbiAXUni (ORCPT + 99 others); Mon, 24 Jan 2022 15:43:38 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:50666 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381925AbiAXUY4 (ORCPT ); Mon, 24 Jan 2022 15:24:56 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9771261383; Mon, 24 Jan 2022 20:24:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DCC1C340E5; Mon, 24 Jan 2022 20:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055895; bh=ywvwEwdbHU5wOPoIxh/ANzlr4vblBlzIaHREvpeMLtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mIm69H7CIMECbVhqCBQsXQ7S3yT9QO0GEJA0vcCyOkJpX80EEwHPJtBw7bWcrS/1P reHkK3ieZF6uMdU3SQurBZtnEIscvNjvgBz0bo5N/F9UiUBnEhX3NcVH1b7QEgsnxx Hfm6B6ewZ6F83vDrXy+XtcdrxgKURd44jIhGI9Qo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhou Qingyang , Dominik Brodowski , Sasha Levin Subject: [PATCH 5.15 302/846] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region() Date: Mon, 24 Jan 2022 19:36:59 +0100 Message-Id: <20220124184111.322682730@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhou Qingyang [ Upstream commit ca0fe0d7c35c97528bdf621fdca75f13157c27af ] In __nonstatic_find_io_region(), pcmcia_make_resource() is assigned to res and used in pci_bus_alloc_resource(). There is a dereference of res in pci_bus_alloc_resource(), which could lead to a NULL pointer dereference on failure of pcmcia_make_resource(). Fix this bug by adding a check of res. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_PCCARD_NONSTATIC=y show no new warnings, and our static analyzer no longer warns about this code. Fixes: 49b1153adfe1 ("pcmcia: move all pcmcia_resource_ops providers into one module") Signed-off-by: Zhou Qingyang [linux@dominikbrodowski.net: Fix typo in commit message] Signed-off-by: Dominik Brodowski Signed-off-by: Sasha Levin --- drivers/pcmcia/rsrc_nonstatic.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index bb15a8bdbaab5..827ca6e9ee54a 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -690,6 +690,9 @@ static struct resource *__nonstatic_find_io_region(struct pcmcia_socket *s, unsigned long min = base; int ret; + if (!res) + return NULL; + data.mask = align - 1; data.offset = base & data.mask; data.map = &s_data->io_db; -- 2.34.1