Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3563587pxb; Mon, 24 Jan 2022 12:18:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxh0YbXW1zhEQwbBgAeKjzLh/7Y++hFXsajRcsUgNFd/+iGsHw2EQK1j3tIhfIMouqjGbXb X-Received: by 2002:a17:902:d4c1:b0:14b:4a0b:79bd with SMTP id o1-20020a170902d4c100b0014b4a0b79bdmr7171811plg.170.1643055494509; Mon, 24 Jan 2022 12:18:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055494; cv=none; d=google.com; s=arc-20160816; b=CT0xfL4JBdo6Lof351xfSmrwYVEJkvN2p4wifrGK2Ubgn2hLp5tDO8E2JMQSrF6Oxz +WlwGkW95KHdz+W8uZ0qZ9gCRXX0BqRzMwsbKxSjBgXVFMR2agTrZNkQsmlLKeyOTilz bWVs90u7/1T6WceESPX+kLpoQm1NYKchyhN76WTXY2k+dhPo2IoLX821vJIwc2OcIMFs obNXzSXQiWD66KyX2IVU4/RyDM88ayq3s8L2n1zp91P8QYJ9vyEsTDUfI23TjqATIbFv 4gMnzfh+qBCC7/+cHLVTppCjcWtKv6VvuJU944OC1DLnS/R2fLn3LMi/NRjEvpFO3HAh nXpQ== 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=QrQwc9vxJ7o1wPq1kvZa12i60/KQ1arepnYJ0FsbmxQ=; b=a6u9aq3Va+d1FinAkVpvz1dOQnCJps0wKLQxzn1eHRPe4Z6Tp2MGQT2w7YblaU+cu1 lBfg3ymGzKo5Ut1ryNhBEuC3Peo87G4G0LXz0PZG3rux7BNCyMPz54D450Fr+AO9sqLB RSKXTsUcTbK+4dqqMOI528JndpnqJOTVvMDtP7Sk0cWq5epzL8keOVB0uksfK4BTOwqE QHn3iZ94TrdHCcqh3XxxNrAGYAIUG3DmnFIva6ID8+IDe5rBIV3CRjTcK379VUPXC8hD kuK2jJjc3ISVIbkB/Wi1uouKBqtSurLlYuOiM2DpPvahjZm9yQn7pGqQe7A4rXWSIo9Q 47JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JIHHH5rD; 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 f5si15361874pgl.459.2022.01.24.12.18.02; Mon, 24 Jan 2022 12:18: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=JIHHH5rD; 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 S1349813AbiAXTVW (ORCPT + 99 others); Mon, 24 Jan 2022 14:21:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239892AbiAXTNT (ORCPT ); Mon, 24 Jan 2022 14:13:19 -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 0BCE5C061749; Mon, 24 Jan 2022 11:05:17 -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 9F0DC60E8D; Mon, 24 Jan 2022 19:05:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C0E8C340E5; Mon, 24 Jan 2022 19:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051116; bh=WwExldU9G39L2ssPdcPuqzKK5FM6hA2PmC/gQghHkmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JIHHH5rDWiea/AorydXujGo/UeXikfW6eSUd+c16YOezyQZmCUvP7xEco5JbmhvJK Yw4Dqxb8gk8IY2ey70m556wG0vNpNTB9aAAZCrOC5b3vsg5HcYO6LJsZ7WJ37CMvY8 16F3EJYtLiZEF3WxfqvfWeY2kQxuz41dwv8cf1og= 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 4.14 059/186] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in nonstatic_find_mem_region() Date: Mon, 24 Jan 2022 19:42:14 +0100 Message-Id: <20220124183939.025695500@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@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 4d244014f423f..2e96d9273b780 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -815,6 +815,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