Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp61110lfe; Fri, 15 Apr 2022 19:32:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrcKMKZefcvaPTkcgXb21KaDeV1pRHlBErcikAvTMoKNPrFGK0xH8DWCE7OdejOxRbkLuy X-Received: by 2002:a17:902:d2c3:b0:158:96c2:6631 with SMTP id n3-20020a170902d2c300b0015896c26631mr1751848plc.11.1650076344104; Fri, 15 Apr 2022 19:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076344; cv=none; d=google.com; s=arc-20160816; b=wlBs0b1K9cMgaic303WyFIGoXLextXR3yPhFQJ1FaTtTwgqiXRPGLGuWUBG9O3DnDV n120NSUxvNZddc8nXf8lkWaGCMEQH9V2+TkQ2JYFcPytNPEtQbPZb4viMOU42qfeGBFd W/tKfe6poLWtDub0PTCRLwqiZSDM4hMJ/jvN5jkj7f/EHcC+Nb0PGoJxSpyW1dNIHg16 zY5Hs7NreX+lYIEIsHvIZrBxT5R44n8BEzNz2Sptrg9Rv/5roYLDriAUVbzq2Nr46Qbs k6V8eBhUJqNoKAIhapL8yeFYPiWpa7ddQzN1KgegHyy7ezRT7c+Wsu+Ea1ttb9yVqnSD jBNA== 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=2+vbWbr69RAj+3XVpGOU2Oap1pYEf0AaBpcHF+8DsNY=; b=sAbZp1352fiL45zvFIE4HonCaUDZdwnksbRb6CHqrYjhNfqV/xU20Ota5WEmKxT0u2 u2oCsOtuTo5V144x6PQ/Be49S1/aaQuQ4KzKVisly5vu5W3JdsQ8dBFOKPiVB+SFoJR3 u1NQ8KlJ1YYk3OayFFrsHV4yGQnM3spmPFEaAGK59h0NOmNWEJmqt9CoGs4fgEU80HDC vqZogigO+ketwfTAYnHlJ3rXIxqkTQjgrAT87U5fIQzjOhRTPFIWWLtnAdpGavfsiS3y 6neWRHuH5pbzpXwMhT40+TdyVJXNMB6YwiSJqmCSKvFq5ayL7bvOB7BQqB2kDqPTv0+X oxGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TRno+SjD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s9-20020a170902a50900b00158b603b0aesi2543736plq.589.2022.04.15.19.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:32:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TRno+SjD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 78E6DD598D; Fri, 15 Apr 2022 18:42:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347228AbiDNN6j (ORCPT + 99 others); Thu, 14 Apr 2022 09:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344355AbiDNNbq (ORCPT ); Thu, 14 Apr 2022 09:31:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCBA9297; Thu, 14 Apr 2022 06:29:20 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5ADF9619FC; Thu, 14 Apr 2022 13:29:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D80FC385A1; Thu, 14 Apr 2022 13:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649942959; bh=PoYRFGU0GjJBUUHKvDBhsqlm12snxwq8S3uEQtl9yfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TRno+SjDBokNLlVP7G85igtvpTchnO8DX1XubKt4Nc+TJ44L3BL6+PApFnZrS36HX hW1sqqqn5CNoTxe5hP+pwywa+wvPAj8euUV5sBRUUABPZZGWv9UbSllU2sm6/k/YtU cA1n0wsALRJ6ujk45E9tOOjTNidpHxkvcvDCRxgY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Lamparter , Damien Le Moal , stable@kernel.org Subject: [PATCH 4.19 321/338] ata: sata_dwc_460ex: Fix crash due to OOB write Date: Thu, 14 Apr 2022 15:13:44 +0200 Message-Id: <20220414110848.025150856@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110838.883074566@linuxfoundation.org> References: <20220414110838.883074566@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Christian Lamparter commit 7aa8104a554713b685db729e66511b93d989dd6a upstream. the driver uses libata's "tag" values from in various arrays. Since the mentioned patch bumped the ATA_TAG_INTERNAL to 32, the value of the SATA_DWC_QCMD_MAX needs to account for that. Otherwise ATA_TAG_INTERNAL usage cause similar crashes like this as reported by Tice Rex on the OpenWrt Forum and reproduced (with symbols) here: | BUG: Kernel NULL pointer dereference at 0x00000000 | Faulting instruction address: 0xc03ed4b8 | Oops: Kernel access of bad area, sig: 11 [#1] | BE PAGE_SIZE=4K PowerPC 44x Platform | CPU: 0 PID: 362 Comm: scsi_eh_1 Not tainted 5.4.163 #0 | NIP: c03ed4b8 LR: c03d27e8 CTR: c03ed36c | REGS: cfa59950 TRAP: 0300 Not tainted (5.4.163) | MSR: 00021000 CR: 42000222 XER: 00000000 | DEAR: 00000000 ESR: 00000000 | GPR00: c03d27e8 cfa59a08 cfa55fe0 00000000 0fa46bc0 [...] | [..] | NIP [c03ed4b8] sata_dwc_qc_issue+0x14c/0x254 | LR [c03d27e8] ata_qc_issue+0x1c8/0x2dc | Call Trace: | [cfa59a08] [c003f4e0] __cancel_work_timer+0x124/0x194 (unreliable) | [cfa59a78] [c03d27e8] ata_qc_issue+0x1c8/0x2dc | [cfa59a98] [c03d2b3c] ata_exec_internal_sg+0x240/0x524 | [cfa59b08] [c03d2e98] ata_exec_internal+0x78/0xe0 | [cfa59b58] [c03d30fc] ata_read_log_page.part.38+0x1dc/0x204 | [cfa59bc8] [c03d324c] ata_identify_page_supported+0x68/0x130 | [...] This is because sata_dwc_dma_xfer_complete() NULLs the dma_pending's next neighbour "chan" (a *dma_chan struct) in this '32' case right here (line ~735): > hsdevp->dma_pending[tag] = SATA_DWC_DMA_PENDING_NONE; Then the next time, a dma gets issued; dma_dwc_xfer_setup() passes the NULL'd hsdevp->chan to the dmaengine_slave_config() which then causes the crash. With this patch, SATA_DWC_QCMD_MAX is now set to ATA_MAX_QUEUE + 1. This avoids the OOB. But please note, there was a worthwhile discussion on what ATA_TAG_INTERNAL and ATA_MAX_QUEUE is. And why there should not be a "fake" 33 command-long queue size. Ideally, the dw driver should account for the ATA_TAG_INTERNAL. In Damien Le Moal's words: "... having looked at the driver, it is a bigger change than just faking a 33rd "tag" that is in fact not a command tag at all." Fixes: 28361c403683c ("libata: add extra internal command") Cc: stable@kernel.org # 4.18+ BugLink: https://github.com/openwrt/openwrt/issues/9505 Signed-off-by: Christian Lamparter Signed-off-by: Damien Le Moal Signed-off-by: Greg Kroah-Hartman --- drivers/ata/sata_dwc_460ex.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/ata/sata_dwc_460ex.c +++ b/drivers/ata/sata_dwc_460ex.c @@ -149,7 +149,11 @@ struct sata_dwc_device { #endif }; -#define SATA_DWC_QCMD_MAX 32 +/* + * Allow one extra special slot for commands and DMA management + * to account for libata internal commands. + */ +#define SATA_DWC_QCMD_MAX (ATA_MAX_QUEUE + 1) struct sata_dwc_device_port { struct sata_dwc_device *hsdev;