Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3592665pxb; Mon, 24 Jan 2022 13:03:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJykt2mwlgKgZxsFvqnhri5tXVtFIknusXlRePWqqy2tRfpuZeCY2T5Dq4JTly2evOlVvMKH X-Received: by 2002:a17:90a:9291:: with SMTP id n17mr145542pjo.187.1643058191314; Mon, 24 Jan 2022 13:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058191; cv=none; d=google.com; s=arc-20160816; b=ACoB7oeYSSENTT/Z/LGcNL/TqKaiX/dlABfOuy4kW/sVIkKHU4c8VPPO1KSC+mss7A udGF4O7vJXkmDHLNTJKU68YXdK10GDIkj/lTsmVeo7ngRrDiTTAmlEGYavDm27jdY1Il l73MdHxpVyAQEXetz09UY5cVVJfCkaZaFkq9ClS4p6qEz+LH+OdPYSZkJ7zuzs0yz6lj m01e7PT2KqKdShiJDcUj5id8rySpZ4nVhKLkdPEwhfdkHw+heW5kJPp+S3JwTpVfMT6x N/ZWOxZBgxiLnm/1fc7BuLizU7dZFBL5ROe1MpyXrLKhqi+s7M3p6OEO1LM+swjE2EGy NbWw== 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=Q0lzytp6Zj5n3qmOQvMlnpYUo604aHpyWyKuM2/zBR4=; b=JpHlMZMuf7QXPVt6NRtWpMoiactF6o/etcOhGqxOTC/s+t9UFVIEy+wx0TR/Dhntrh 3EV0ocT75jzm4aRzg32Tx+A6in05J5Aw/KHM2EmJC5sLqWfS50b2C14teZ7ObWP0dUOK IcEz6Bat2rvHvce4CLSVTTCM1BD05PM4oz9ZPvthgHkkx5WKlBiTe1KD0rOtjKMwq36K QHC5T4WpvYUwgXD2HNFUQqU9a67LH4MWj+MWrVJCh5+5VyERIHUnqwygwg80KttTVsO1 JXQ2rkqgaizdyeCzoX6CkoEWXxO29sQwVlXNPCi6Z+OIP60myD0jwZaB/bO0Da0jRNpX QlXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WV2V45wl; 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 q4si12904523pln.98.2022.01.24.13.02.57; Mon, 24 Jan 2022 13:03:11 -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=WV2V45wl; 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 S1382079AbiAXUZL (ORCPT + 99 others); Mon, 24 Jan 2022 15:25:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377247AbiAXUFL (ORCPT ); Mon, 24 Jan 2022 15:05:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D2CC06135D; Mon, 24 Jan 2022 11:31:02 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1443260917; Mon, 24 Jan 2022 19:31:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE52FC340E5; Mon, 24 Jan 2022 19:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052661; bh=QIyd7AmQlyQIzFlmmWqrWVw2aKTPMcJgj11z4fSzelI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WV2V45wl4kRDANKFjenzAB8hocD8El1rmI/BMFpN8YukKGhGIRoSsnKgTOpAEYciU agLcExrFdk4e4mMQ6DxbSGztr5FxbVR7/ExnasXssqFCE5ZfcV0nDVDy5XsQc1Zbys sgoIsURtvJjVVVCUK5q9hFxnOTQP3ZM9O63+bc7Q= 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.4 100/320] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in nonstatic_find_mem_region() Date: Mon, 24 Jan 2022 19:41:24 +0100 Message-Id: <20220124183957.128914925@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 03ae998675e87..3a512513cb32f 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