Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3610105pxb; Mon, 24 Jan 2022 13:28:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjiPXH+kbcRYQXHevkWFltVrU07sPis9Ik3JFZmy1hedO60fDruEZe+hTuPHRHGgXAUfHQ X-Received: by 2002:a17:90a:560c:: with SMTP id r12mr243076pjf.33.1643059693758; Mon, 24 Jan 2022 13:28:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643059693; cv=none; d=google.com; s=arc-20160816; b=mLyrYaz1XaWs/bFmizAZhwrcVS3r69TNgp2iiwpyfMt9c1YtKE2WMGHrjquP58S7Hn 54HqSEesM6jWpSN4X1pfVWAQ4WdgTfg0z90qhg1LDRNcMj60YCn4ofOE8WAEPGcBqbry VU7dHpH8wUhFgfz2OwLOZTeV9tV7oSfarmJBW8BHK/lvKA0UJs5M3JY7d/oZ5QE+IS+7 JbU0kGwMQ4J9+txdWC/DN3lIOwHOnTM6dXHzrLGzberg+G6Q/oDD2bI2ZAyu90+cP6nr FnfgXR+9DvVWe82ofh4vRXjPB61p+/7htaYZTGJMEsCMWrh2PvHgqibLKdV1Q5KtGWQE sRdA== 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=q0Hf0aT+Ui4V0Q8a6YUFQQ5UUvOV4RVtYM5HJ5yTmxg=; b=KMjSDQ1SeHWlIwrxOomFEDXO0k3sScwP1+D2Qib93Ptop1iX2f8eD4eG8cGSoAEyfg uUgebM/+dgvVdfN1xWbv/H7cufTVQ5GLwl9E02pwdc9VBPB5ZTXt0eX+mun4JWkll9YM vcf0DUSS/PWEpWRP6ZwLKaityJgzvLA6BbbDKUwYNBVmJ6hM5lNCxJdq65LgwpCD8noa peamaM3BVS8AAZ2wcv+QkPG4dPLt682LXG0MpkX6M/iOVyHkV0QeIYmTKpOunYdhuG8O 3o25HNx4lwMRAwYgQRbJavTaV8nVU/ZbtRtTnPUkELsJltxd6z7RAGLsIX/IMY/XseQ6 K3Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Za3NeUYm; 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 67si16067687pgi.130.2022.01.24.13.28.01; Mon, 24 Jan 2022 13:28:13 -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=Za3NeUYm; 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 S1444971AbiAXVBt (ORCPT + 99 others); Mon, 24 Jan 2022 16:01:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388375AbiAXUiz (ORCPT ); Mon, 24 Jan 2022 15:38: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 86943C024148; Mon, 24 Jan 2022 11:51:08 -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 45532B81142; Mon, 24 Jan 2022 19:51:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75B4BC36AE9; Mon, 24 Jan 2022 19:51:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643053866; bh=jnFAsEx811A4DvqvXcfMvJ1VJaWvTEwoxEVEJIk2m+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Za3NeUYmEKsROe1jXpK4KrYoD93CE8/eicHu3tTez0ZmoyE7FuRlZb0WI5PT3jE1o X3SsEr2myDbduswKdI2JHvwAmvY+Uj5faLutCTwXnaYvIo6X2P/F18H/T+FP+//3KM xGGUntxOEtTSfIrWo50SegGIL84yWYUiXGoTjczA= 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 202/563] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in nonstatic_find_mem_region() Date: Mon, 24 Jan 2022 19:39:27 +0100 Message-Id: <20220124184031.413510994@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 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 4c70e8ffe04ea..69a6e9a5d6d26 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