From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6361AC3A5A3 for ; Tue, 27 Aug 2019 08:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 36FA82186A for ; Tue, 27 Aug 2019 08:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893050; bh=EckM6EaT5wZqSIkZEo54Rgu+k2ypMTKdIE9vRi5T4LE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=paXuTmE8woSd/Uo4vzWs+DJ1tX25mHPBI638nKDk1hbznQXtdeFZOMN49RO42sGu7 j7pfBxL57s+uZhhWiq8Q5gsleuBrQY3E7vi7pFHmCSyYvHKBERki+xonGIRcyWLl1P /kNW5J+RpiFDjuWPLmmMbd6YMPIgVeIbJmZEVbVo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731666AbfH0IEJ (ORCPT ); Tue, 27 Aug 2019 04:04:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:33308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730433AbfH0IEC (ORCPT ); Tue, 27 Aug 2019 04:04:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 277A4206BF; Tue, 27 Aug 2019 08:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893041; bh=EckM6EaT5wZqSIkZEo54Rgu+k2ypMTKdIE9vRi5T4LE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vuizu/5aQTBxt1MzQcnG4Exlo7sMKG8rQWL6CY+RRZHu4v9oK9VswIaFwYZ+vzWFx fqlH6upaV0oz2JclAyb4fAxEcDI2nhPUIhr37qfgaf1fmibbSh5ADtayijFNC7jm9z PhGUjdB/iCre8HQlSUfAqnsNC5A2I/8nCxrKZBJI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Jens Axboe , Sasha Levin Subject: [PATCH 5.2 098/162] libata: add SG safety checks in SFF pio transfers Date: Tue, 27 Aug 2019 09:50:26 +0200 Message-Id: <20190827072741.639793873@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 752ead44491e8c91e14d7079625c5916b30921c5 ] Abort processing of a command if we run out of mapped data in the SG list. This should never happen, but a previous bug caused it to be possible. Play it safe and attempt to abort nicely if we don't have more SG segments left. Reviewed-by: Kees Cook Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/ata/libata-sff.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index 10aa278821427..4f115adb4ee83 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c @@ -658,6 +658,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) unsigned int offset; unsigned char *buf; + if (!qc->cursg) { + qc->curbytes = qc->nbytes; + return; + } if (qc->curbytes == qc->nbytes - qc->sect_size) ap->hsm_task_state = HSM_ST_LAST; @@ -683,6 +687,8 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) if (qc->cursg_ofs == qc->cursg->length) { qc->cursg = sg_next(qc->cursg); + if (!qc->cursg) + ap->hsm_task_state = HSM_ST_LAST; qc->cursg_ofs = 0; } } -- 2.20.1