Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6146275iog; Thu, 23 Jun 2022 12:17:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uWVUPFrFkuSKAfII6t8dY6j7gHnLPPSs5s2e9GueLy5XM7ohYyOVLAPePFBhq/G/xHhayd X-Received: by 2002:a63:1c45:0:b0:408:8af8:2d1e with SMTP id c5-20020a631c45000000b004088af82d1emr8715877pgm.52.1656011878370; Thu, 23 Jun 2022 12:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011878; cv=none; d=google.com; s=arc-20160816; b=w08gmj+1TQ9++FxhL2NlaNzfme7Fh9p2gbK3TBLsUdn8I7SQPwJ7+d+j79j0Eo9pj+ tj7k81jxBcctBN1SYzMyN5zFynqryzdkHIo9hRfuDWynnQ2VNG4tdjHomZCwdSqy8bZR Lyfs6TZRttnSFek6pvjBt0Jh1uB5t/CcmbEKWBnPwglF6Ky77UZO4AXPsLPv8sOgfMgt HWdBvvAZ1yQc6jEKOw09npFtH9ozFWRLsKFilir68dcpSr8zLvol3kuaJoBX6ZvAhLOv cL9Fp9OoR81RkSThvwTUnZXVvNdUzWtOZpIwAwzmbpwWbp5K7D3AOOVq+4EcoafdYMgt ekFw== 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=4aGWWqXOVILJX7w61IKQUerYeXBUvstQl8989UbZ+e8=; b=OlSwJH8AxsYRc7PKqBuQDs8c3OBrohlWpGTL2F7QoT4EIjODq33kyd4lzh5k/eujwF AYFLeB94lnnJW6FF4pGbJLHvHkJ8ATQEVRApqEL2+KFJl5ZkKoUnJx5ioR2DaYEQ1zE1 0cL4okLIsDqonptMn+148E/yUPQY3YT+AjWiwOFm89YBztQY+QWv9OXWJfx9pOcxU17H RgcPyeJRPu0yUbGKxzyi1myN9zn+JRAogbqtw/+4up5sC654imWjPAEwxJW7+tfCoKU2 JC8Y2bkgIQtl/fUNiWK3w92eHvA4MVRhLPtLSFqvbFV2lj1vZbqSlaAaVNRcSLZmGm3A gRww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DNDPWbuT; 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 j3-20020a170903028300b0016a1f3f7c57si368939plr.607.2022.06.23.12.17.46; Thu, 23 Jun 2022 12:17:58 -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=DNDPWbuT; 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 S232342AbiFWSPt (ORCPT + 99 others); Thu, 23 Jun 2022 14:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236586AbiFWSPJ (ORCPT ); Thu, 23 Jun 2022 14:15:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D917282887; Thu, 23 Jun 2022 10:21:42 -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 5D28CB82490; Thu, 23 Jun 2022 17:21:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC092C3411B; Thu, 23 Jun 2022 17:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004900; bh=2NaLsw+VKS3gezcd5noKb0OnET71MfjOfMTBsv/wb2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DNDPWbuTYexF0eosoOH2FzGHTYDH65cs8S6b2ukT5i7LhII8kXQHBQKl/twgYlH3T QaTuKyMe7yN6EqGa3yGEvJZNm8StK2BWBa4rjVInGsBlChx6DJUMIRpJGQ7zSRNaN9 BE6LAt3FBe9DdhvgUQnq7NBA0vkD3k2TNUi8SERg= 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 4.19 186/234] ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo() Date: Thu, 23 Jun 2022 18:44:13 +0200 Message-Id: <20220623164348.313001396@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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 0c10d9557754..b0dea0702c74 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6253,7 +6253,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; @@ -6261,7 +6261,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