Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3548206pxb; Mon, 24 Jan 2022 11:58:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzszwUIWM77c/L5aKgoFfssA43yoM4t0KzgeU6AHBOO6acnxus+lmhfIxTKr/mdTOciI8CX X-Received: by 2002:a17:90b:4c8e:: with SMTP id my14mr63278pjb.0.1643054213301; Mon, 24 Jan 2022 11:56:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054213; cv=none; d=google.com; s=arc-20160816; b=jxtn5KfelfaEE6bbvLNcl0IzpeCDdx2M0RXUl9URehSRSq0WUhE3CinxaAFVtreOmD /NfIMcjBpoUTe+YKRCZRoWlJZalROmXUapFHGeXAZBPx5WVqkiRsNHj6VydWw0BtPfVA 8tmutd5vo4k8KNG1AasCzncf/KgWOeyaOWMtE5UMvo8tCo0h4ksAsAyDwmkmfIeHaaEz 4hunDtXtKxPm4jUNBlx6qC+rpIhZ9yacOZOYlsHWBtG3P75YHLQo0yw4Bim8Ojy1X8yb kfa4TVquWIRNRhFSxvcRHp6bYBvFUxtk+TqwaKOSTC09Kw6POnB4TvAMzFiLVS04EIYl KaAA== 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=z3PvRGpRVY6aGfMLFlv2ycgCXodgUXGHJDoRNBVQhKo=; b=cD6+EW+czqy4scV1e/rGf9SUtlncMqD3245cm78sw/YfcYpSifMlwMrw+pkrVY/NC+ x8RMN/9l9kvCFm5IUDf6SKkhMtUNPagfaNqjUOsRUjp1hyo8Kvp63ZnLATNX1WO3IOSC clcTL6q6rd/9oro+fO3+5O8Nu9OKBPSX3D5u7PPjgX9e4wOCAT27++hhzDgqQp5MD62m xqDShUUDgPP3sV0F1+jGdtRop+lxxBgUdHvkN9IjjgfIJEzuvO0DBu95XK6pn4NG5HBL o1bvZ+Bch1KTJoZI4ggiLGeGG211Id0lG3ZOF1B3++qJYXiJPhj88xcO0VBSvTMaDXc5 1fnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LMM3g83V; 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 ij25si12829305plb.514.2022.01.24.11.56.39; Mon, 24 Jan 2022 11:56:53 -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=LMM3g83V; 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 S236669AbiAXSur (ORCPT + 99 others); Mon, 24 Jan 2022 13:50:47 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:49604 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245520AbiAXStj (ORCPT ); Mon, 24 Jan 2022 13:49:39 -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 3DF00B81221; Mon, 24 Jan 2022 18:49:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F3A5C340E5; Mon, 24 Jan 2022 18:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050177; bh=IyEZm5VJ9DTUvGD5ch3pdHZ+oyGhrNtAXW8JkE7kfH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LMM3g83VQvVgGF5G64GlaIBPJIvwbwi1DNMvYmCWb1665jD/vm/z5w9Zlu8tOW7Rt mz4zRAbfIMwPsVU0QG+C4ihF3muHg2BNUeWZohkjCDmWqER4rfUhkckYdeXXL4dOK1 0Qy9NEJVWROCyJOwM9eI9FhaIEBoVgR24zL8owE0= 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.4 034/114] pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region() Date: Mon, 24 Jan 2022 19:42:09 +0100 Message-Id: <20220124183928.169382566@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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 5ef7b46a25786..4d244014f423f 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -693,6 +693,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