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=unavailable 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 E0BE6C3A5A6 for ; Tue, 27 Aug 2019 08:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD7BF2186A for ; Tue, 27 Aug 2019 08:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893651; bh=lzl8BcBYP0c3jub2A0I3vQHJD7YLGW+voWziaeK5n+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JtLQZiBEGI4DPI4RWdNH/n+jv5NSoCOdk2n96yySB9Bnm6r+cnu4OpGz8/opqAJTe nJhkGme9EFCiofV93FqwKnxvg7/JNRdQ9PO/Vnw4/f2iSqtQXSj3FUYl3/WDtO/MJE OjKo4xi6ZkU6r84b/wxNQeoOu0q3e4rMd+vBt2CA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729268AbfH0H4s (ORCPT ); Tue, 27 Aug 2019 03:56:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:48896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730698AbfH0H4s (ORCPT ); Tue, 27 Aug 2019 03:56:48 -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 E7F10206BA; Tue, 27 Aug 2019 07:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892607; bh=lzl8BcBYP0c3jub2A0I3vQHJD7YLGW+voWziaeK5n+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WTUPcnUOYjVGV4x+LQi5gyWrVzX+UlAXbitPohjlFGqlI0ytruZD4ZeN0sxcZnYy5 bqNdha/XJXJYWxiz89W6oXtnU7BZqczM8bkm3XzCbauPKK0meD3e7eGz3hRQy8jbmo x/DgO7VROmNK4Z44Cge562/4SXYPgaVF/XnmhL2w= 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 4.19 49/98] libata: add SG safety checks in SFF pio transfers Date: Tue, 27 Aug 2019 09:50:28 +0200 Message-Id: <20190827072720.918419073@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072718.142728620@linuxfoundation.org> References: <20190827072718.142728620@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 c5ea0fc635e54..873cc09060551 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c @@ -674,6 +674,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; @@ -699,6 +703,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