Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2932963iog; Mon, 20 Jun 2022 07:46:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tVSJpbiJC9xcW7Exz3W2YF74HGAUVnjB5rdSdPqKBAgcOYwaVko6fW5fwv4q6iX4tnihgB X-Received: by 2002:a17:902:f70a:b0:16a:38b:18ad with SMTP id h10-20020a170902f70a00b0016a038b18admr18567401plo.64.1655736378605; Mon, 20 Jun 2022 07:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736378; cv=none; d=google.com; s=arc-20160816; b=CbckRBpQu1tN72zN/gQfImXoTadX7dl+1nP3aN/pndVncSbv0R3yc1Awc8IkjPJ56q 1fMOs+u3SaB0SpWb2VnEUFn0Tg4KpqxP3YNwYYc0Cw4a+GWpLYINP7WoXzfe20K0moih ldaYtQRsrfzwJYqOF0yLi6J1sHXPHhQaaF7+uNBkcG7oqltJCcOMa959IuFbjfIzBh5d t+to2VAqW9sVK1W9ORgOS4Qk9BjdNODI4L7+wO8fwv6qXrfF89BcfSmFIXpZoxwERfXX pzDQI2026WhaBkMfwEDwxpjhuwfzCN9LsaiQr6XCk3U4IJ0YkBPAO4WBau3FeAxDIuz+ KEqg== 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=UpE7qulNedTBkE1DOxyoTsx64oOiW1Ng3Z5256sW9ww=; b=hWtivpfxMg1redvgzMTw1M9j5yhxefG31Oz1kzrZGTCuXHOfyubHeb/GNqZ/bffk+B E5jR6BUi7mSN4xTIKqS6ra40dX7GUwNYw2JYQwhDiF9zXJMpf/cd/sVJKv7gUR7ko/R4 fd4ofqYRcQdyIJgkgZHn9BDPN8c/h35KJkz6nSoupbOi5JQ7yjvbR3dDbdaQOF5f+94V fuoYlcL861HAtbyK7GP+K9SBvvnc8IjZ2W9trT//9/j/udO2loFrPHXM6ozXnWttOERT MR6m3KACYyFPcuF+/WzcHIZ4C3MnsM4o5lG4pUdue3z6UO6qfVY1pYCFWSkwYXJ6jnMS o5yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XtJb6mvV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i1-20020a17090332c100b0015d3604e495si18109471plr.165.2022.06.20.07.46.04; Mon, 20 Jun 2022 07:46:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XtJb6mvV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S241908AbiFTMyG (ORCPT + 99 others); Mon, 20 Jun 2022 08:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242912AbiFTMxo (ORCPT ); Mon, 20 Jun 2022 08:53:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74CB1140A7; Mon, 20 Jun 2022 05:53:41 -0700 (PDT) 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 35C55B811A2; Mon, 20 Jun 2022 12:53:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7090EC3411B; Mon, 20 Jun 2022 12:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655729618; bh=/S8yQzz0bEZtXnByi4TQCeaXrYJNa/rP7ocesI2o9rc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XtJb6mvVbX+lNZoquJkhEsvdtl+K+Drvsbro7mgbjQmgunvFW3qRXaW9tS7O3WReQ vI/8whB+86LP6xRa0Zi0mv7do2fsyf7R6replqAraWuP3R45AbGG7ow5+MZfLMKuVO M4hVUban8wLHwQfd2U1sJj3Xlct1GrcW/qGmKB0Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sergey Shtylyov , Damien Le Moal , Sasha Levin Subject: [PATCH 5.18 020/141] ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo() Date: Mon, 20 Jun 2022 14:49:18 +0200 Message-Id: <20220620124730.118972624@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124729.509745706@linuxfoundation.org> References: <20220620124729.509745706@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergey Shtylyov [ Upstream commit bf476fe22aa1851bab4728e0c49025a6a0bea307 ] In an unlikely (and probably wrong?) case that the 'ppi' parameter of ata_host_alloc_pinfo() points to an array starting with a NULL pointer, there's going to be a kernel oops as the 'pi' local variable won't get reassigned from the initial value of NULL. Initialize 'pi' instead to '&ata_dummy_port_info' to fix the possible kernel oops for good... Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Signed-off-by: Sergey Shtylyov Signed-off-by: Damien Le Moal Signed-off-by: Sasha Levin --- drivers/ata/libata-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 3d57fa84e2be..ea9671821258 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5506,7 +5506,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, const struct ata_port_info * const * ppi, int n_ports) { - const struct ata_port_info *pi; + const struct ata_port_info *pi = &ata_dummy_port_info; struct ata_host *host; int i, j; @@ -5514,7 +5514,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, if (!host) return NULL; - for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { + for (i = 0, j = 0; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; if (ppi[j]) -- 2.35.1