Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3654549pxb; Mon, 24 Jan 2022 14:32:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxF34xyAbWObrQhnLwvq0wwun/7pqsa+kw6gLuL8dtShti7LZPehyxTA4UpiU3wj5896TZ X-Received: by 2002:a17:903:11cf:b0:149:a17a:361b with SMTP id q15-20020a17090311cf00b00149a17a361bmr16578057plh.146.1643063472132; Mon, 24 Jan 2022 14:31:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063472; cv=none; d=google.com; s=arc-20160816; b=Pd+2z0ojMDqdjpbHOoePOOGEhWlGyOJRXssCvKJ1gAi+nZe4XOq+DE2ae3T8uDUZG6 v/WJyIqbl0gp8Sbjh1giMczG3mPcX0kbr/HvgFSH/3F4OCcayquYkT6ZcrKe/RDZHv1e dDPA2vZLndHgd3aYOHgdbTEDfrXMkYeCu1CgormCkx3ga63Xcjz81SvtM1oNNhkQAfaq 8SwS7mfjiO25RPzCUF5NnufoeuCNX2gSc21tN1GF+vJIi2SPQoUzV7RXb2aQDxCxEqjX NzRZcjTNybJbpXJYXO6OOwltv1Rl0/wKjhIZFMtZ4EPOZQ5+GoZU+Ix7g5mOig46NEJ/ uloQ== 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=tMHTDGN33ScVk54R70Cq1PI3ERf+01w1XTgPTWgrvwE=; b=lL6bg8h+TxoPjpZKBKQUFkmn5/pCshTsI1aaUzj641QwlVKnmFeseUWZsodjoBeeEJ N8jjkORO/yzBC239n7geNKplng0lY8K2rJ6EXyTNGroO8rnU/Fji6tvNTwPvFOV4orHf kaYft2Ax30ygrNV49DST9ZjDSIyzv9ylDSjSmQ4gxytskxkcUe7DWJ6LbP12IcxD6A15 qS2eeknr0sv0mmBEl43n5MrwSOv7RLd/GGQdysnoAtSGIYZPTQvbaEEYmasRkyfDVzQr 4Qdb59uTtr+iQs1WN7tsBCkbvFww6xeP4Zhy8vaJjBiT1gIQABqjpNhExnlwiW0qvl8R py9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kYz2fBU9; 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 e15si16040304plh.547.2022.01.24.14.31.00; Mon, 24 Jan 2022 14:31:12 -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=kYz2fBU9; 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 S1586797AbiAXW1V (ORCPT + 99 others); Mon, 24 Jan 2022 17:27:21 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:33426 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1447726AbiAXVLY (ORCPT ); Mon, 24 Jan 2022 16:11:24 -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 ams.source.kernel.org (Postfix) with ESMTPS id 666F8B8105C; Mon, 24 Jan 2022 21:11:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 915CCC340E5; Mon, 24 Jan 2022 21:11:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058681; bh=HDH01BdQbtjtxDwLkE394xgNnK/+LbYUX8kUZZULQ84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kYz2fBU99AXAyEVKfL7qlu4e0FamZrNlc6uHgWL46wNGxlH3PHKlYHEH5beq/UTro xxGOgZNrBWgfrl6YOd0eI5uNwYWaO3YNZQhgIJkRpPSER+IHDEhX0DMAD492AC/WHF 3WAIgxpC2yjGiDIUHHk7ztgycCFpfVlgdxwxKAbU= 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.16 0366/1039] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in nonstatic_find_mem_region() Date: Mon, 24 Jan 2022 19:35:55 +0100 Message-Id: <20220124184137.590156427@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 977d2e7c63c3d04d07ba340b39987742e3241554 ] In nonstatic_find_mem_region(), pcmcia_make_resource() is assigned to res and used in pci_bus_alloc_resource(). There 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 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 827ca6e9ee54a..1cac528707111 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -812,6 +812,9 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num, unsigned long min, max; int ret, i, j; + if (!res) + return NULL; + low = low || !(s->features & SS_CAP_PAGE_REGS); data.mask = align - 1; -- 2.34.1