Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1897694pxk; Tue, 1 Sep 2020 10:17:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeTfMKaZp4CeBvM3SLegycFmMSj2dhSwjvYBde6LD0hT185TLnAyvnTa+cmkwXagJVeiqY X-Received: by 2002:a17:906:f747:: with SMTP id jp7mr2358864ejb.22.1598980638352; Tue, 01 Sep 2020 10:17:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598980638; cv=none; d=google.com; s=arc-20160816; b=iPQHQgE7Ah/rLyhlNeMdVcWhhLayWQTCY8XVp7ha1lY8AQj0Xyb+GEhE6P/hLoCJSR imlcAgF54gG5LVvthc5nlpJYYeTQBsiXDire0zBw+vKtQQLYTGwj2v647xDSCV2ryKSf oAgbNRZzR6BfZvejDopS+V8Y7dhFnb2GoIlAIAWM57HMSFZ7DlrGYUV5sBFBDxpzxGev G/CS/8bRxHXPHGOkK4Z06LK5nqncwoQdgUl7m/IGq28VF+eq4HuSQ3KVw6NkohG/vNN5 CJ1jnill7YxBwxgoGXDYTl/kMw1DPbuVawRBwjwhwramXoMNcgHb9Ht2VPveI8Zynu1u UMGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hzHEEpoz1inkNKGryFpHqU1GGt6x5KE8q4e0vOAenlE=; b=OFfjklZs6MvOeEKTJGCH0tR/Df/jnilq8D4Z048THj0QDcFE5dyOiFrjSNqZHqhm6c vuLC5HE2owvtETw9jCO/nWugY+ZsXQndE+CghVPwdQ956sb1VwPRU7rfXaSmuW0INlXw zrFOAZcjlHzJYgnSbWCeeS4ZVqPeMbHKFSxQDCV6RyL3kKSJpsvfDtFnuPTY7/7sRvZ+ 7Ga6xHYmsIo5f1UMbLvbmcubGHElomI7nnmIAaX9kF5AT8ONHRbxzaVtkkt53fuJBll1 Pb47Pse5i9RLLA27kXtY9AJBQLRf0tDRq5Snmfi2V7BaSNL42kysALeEJ+muOdZ4Fyfr qsMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WoLm+cPt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j10si1082227ejv.425.2020.09.01.10.16.51; Tue, 01 Sep 2020 10:17:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WoLm+cPt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730120AbgIARQV (ORCPT + 99 others); Tue, 1 Sep 2020 13:16:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:58168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729036AbgIAPO1 (ORCPT ); Tue, 1 Sep 2020 11:14:27 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 182D0206FA; Tue, 1 Sep 2020 15:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973266; bh=xAEgqohY3FdYqYTTjlQYaSeUB4UNZYS7CDwMTrmHEbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WoLm+cPtEYTShMdOTgAGcuwNvmeDBk6QjIvn69SK2hPSZPCy2pMaVq//sP76poYYR nqAYDUBSuGXXw9r3NSZFUollfguVY2vD2QWDI/AD/kxQW6hGyqQ+vo9tKGBYsmjyMi VvDnKELq7v7+6LCqeFfM1V5PakY5Cdz7qk2/kr1M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, JiangYu , Mike Christie , Bodo Stroesser , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 11/78] scsi: target: tcmu: Fix crash on ARM during cmd completion Date: Tue, 1 Sep 2020 17:09:47 +0200 Message-Id: <20200901150925.297380646@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150924.680106554@linuxfoundation.org> References: <20200901150924.680106554@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 From: Bodo Stroesser [ Upstream commit 5a0c256d96f020e4771f6fd5524b80f89a2d3132 ] If tcmu_handle_completions() has to process a padding shorter than sizeof(struct tcmu_cmd_entry), the current call to tcmu_flush_dcache_range() with sizeof(struct tcmu_cmd_entry) as length param is wrong and causes crashes on e.g. ARM, because tcmu_flush_dcache_range() in this case calls flush_dcache_page(vmalloc_to_page(start)); with start being an invalid address above the end of the vmalloc'ed area. The fix is to use the minimum of remaining ring space and sizeof(struct tcmu_cmd_entry) as the length param. The patch was tested on kernel 4.19.118. See https://bugzilla.kernel.org/show_bug.cgi?id=208045#c10 Link: https://lore.kernel.org/r/20200629093756.8947-1-bstroesser@ts.fujitsu.com Tested-by: JiangYu Acked-by: Mike Christie Signed-off-by: Bodo Stroesser Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/target_core_user.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 1a83456a65a00..693fbb2858404 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -666,7 +666,14 @@ static unsigned int tcmu_handle_completions(struct tcmu_dev *udev) struct tcmu_cmd_entry *entry = (void *) mb + CMDR_OFF + udev->cmdr_last_cleaned; struct tcmu_cmd *cmd; - tcmu_flush_dcache_range(entry, sizeof(*entry)); + /* + * Flush max. up to end of cmd ring since current entry might + * be a padding that is shorter than sizeof(*entry) + */ + size_t ring_left = head_to_end(udev->cmdr_last_cleaned, + udev->cmdr_size); + tcmu_flush_dcache_range(entry, ring_left < sizeof(*entry) ? + ring_left : sizeof(*entry)); if (tcmu_hdr_get_op(entry->hdr.len_op) == TCMU_OP_PAD) { UPDATE_HEAD(udev->cmdr_last_cleaned, -- 2.25.1