Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3610114pxb; Mon, 24 Jan 2022 13:28:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGJ2PyIBS9DWrMf0NEAe/OQ0AF7deAJKPI8X+lUIYLwAgFoZvP+C3yg7kR02JFBqy0Tp/w X-Received: by 2002:a63:7110:: with SMTP id m16mr12904628pgc.621.1643059694796; Mon, 24 Jan 2022 13:28:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059694; cv=none; d=google.com; s=arc-20160816; b=piC4in95Arnwn2adI3v1eCKMxP2xNNfV+GLxhJNlCjpq5HDUrtFAqbElxj7O6eqEzn 5rfhY42Z/lsHOG3BGTON+Zo2+xE0oHVgSM45d5TyQN/cIMMXdoAjXNI3o9FpzTVjbKd5 RQxUrmkEDpzoPCQ8zo1R3ob09YBQAXKpBRYT76Xqm08OPqRCyozxjJ1eQ6vqEgCszLEP IV+o6S/yYrMGASpIJ0aMAhz4/v0X4TT0P+UJEmueJHR3SioDTROAp8dB5kU8qZK0Bvtv cJk9H70SNDvg+1RgaMithDZv+gIumPV4rIzamE/IQhzWmuZ2pF3cqNu40EGYyuzrtmyR 1DpQ== 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=CBVsH5MljaWtTNqi1uXImkJ6vpsic2dU93PwtNavgW8=; b=nmJjrLumtscfdk1G7Q9391Zq9OL03wsYGBkD+oGfSGwOTO2K/r0opFuV3zoFiZJvWN nK6ine8vXxDD7vaUxhG0A1ts3uD8whVq6GJNwFK/c//sNAjthO2SDnKOuwTzvHzzTYLc CWCracfGHJk4SPWKsltFuZo60Ra+7us6+GIwZS46AjPWoYfr+WW1Nc2+jwVakbytFoS2 AKzltVwObBCCmcqO8OifjKgwgK1QQT3LYlFlK//w8xCRQ7TJHzZ+ozWgK2yCwtlX7F5v EaPCte9u/LsGSNyhjjTQvRDePaNoMoe0jyF4Uam35qsNHKCdnQyFNvV7TpNQF/JN9nqB E7LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GPm8gwbU; 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 u17si16094148plf.139.2022.01.24.13.28.02; Mon, 24 Jan 2022 13:28:14 -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=GPm8gwbU; 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 S1445437AbiAXVDZ (ORCPT + 99 others); Mon, 24 Jan 2022 16:03:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355210AbiAXUhz (ORCPT ); Mon, 24 Jan 2022 15:37:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF15AC02B8F1; Mon, 24 Jan 2022 11:51:04 -0800 (PST) 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 739A9B810BD; Mon, 24 Jan 2022 19:51:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EB98C340E5; Mon, 24 Jan 2022 19:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643053863; bh=HyqnZj4hnbENVg9FBNZafOFO/KlHBnFYWqWpCss4+bA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GPm8gwbUMbRtaqdagVxZiG3GFgmsOxiOaDssvXvU9IjRGdpj8bagoGBxoGH+ViWRV AFe8FFMVcL4ZyuD3BVNkx5PdXjz18vtrzVpTq9tyYMnxYxbpneFGnaeOr+bOn6UflL Mr7LbWTeJhCgaFzVa+8rfpEG0RoOIYwb8Txb+N6w= 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.10 201/563] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region() Date: Mon, 24 Jan 2022 19:39:26 +0100 Message-Id: <20220124184031.380890377@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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 3b05760e69d62..4c70e8ffe04ea 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