From patchwork Fri Oct 18 10:16:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13841554 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C91482010F8 for ; Fri, 18 Oct 2024 10:17:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729246632; cv=fail; b=pR2QW7gXCyFs4yYZr8kpIy1W0A2VW5VEfLJuoCIABC9VsbgwzuVemgmwpGtIao7Tc2euW3kecUwZy8DCo9QhVG97XbYEdiBmU2Bp32C/yPf50/zB/ZUZSOjM4wkJ23+cu9FG+aTSO0kLaT0RZgdF1Gt5X/w/XnNBe0kIpcBoPhQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729246632; c=relaxed/simple; bh=tr6vP3OgvMczMti2Dh1W2q9eYo5mrdv+dsC6q0QVy98=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=XZhgzNT+WEn4YQoTHKudV9cFC+zipEgseToH1F/Vw2cYSg6decTPDZMkd/1JkUFLKmkp9lj1YgUGTpFYSWwYfvf/gcwXLRGnEuPFWRHWjy0szOa/5AKC4SyZZSYmHJJlh/PoFzynt+LvhY7c9Gl3ZGM4HydYwfro067EKQYFMIQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=POvULESU; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=G75Ex/Pa; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="POvULESU"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="G75Ex/Pa" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49I9iiFI022326; Fri, 18 Oct 2024 10:17:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=corp-2023-11-20; bh=4mRwQKmzZq41ZR1x sbsETIF++Cf9J9Wkz/W9zV9of6o=; b=POvULESUBhxZzsndBfTEOMATcjkEdz2F JV8zYgihLnaR6B5vHRhKrNvPHdrnUFpVmF2fAAEUXuBdq9p7abpKmH7BxMd1eBdW gfODS6ts/yR7EizJ8pKf68rnaqJ5WLW4BdY5DwuqsWCQoLXWLWM9oxD+OjlUeHzt GguNLwSduQfKSXjR4dqWw+8sBvYQ7O8KK9AuauTH+AJxM+Lz/kyBOmm+HWBKeryS vLq2aqLnmdRsP16PyN3cEzABK0qmuN+mIHVV0dxTtmkm3P31BKHJ7B1laUgfnO+Q EmujscrS2FYn0buRRyJhqrKmUKXAqM1JtUCh/OnTZbTk4ZHFFSDP9Q== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427gq7req9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 10:17:06 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49I9x6fM036099; Fri, 18 Oct 2024 10:17:05 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 427fjhy0ce-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Oct 2024 10:17:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HPgd1CQhIBPDglMhM7wM8DgqlOtjytV4RjNCTGy1+Fdz5t6TCAlDy10o46VCAQnCynhwi05QqajM1Kox0sG/7VvXqAMjP8PmScrYhVoH/CJD8DPvCXW0s7Q/xpB3s5pCXX4453Qu1XCPvifxbFI3Xd7+0a7o4CpZWvpda1qTad25/AtO3ARnnWZrUJuboDt29bQsRplSRYl+KV9IZ82CxsG2L2q2pt7O9kVi4Ugl7E+uOrFvHId3HzxzqiHhpSx5a8Ja1LyVXJW/f3AMOxA9A8i6rBmdJITVfBJAIoPZ9eKkXK93bJuCO0eFA9qF+I2Q5rS20Py+VpWJTce27r/NOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4mRwQKmzZq41ZR1xsbsETIF++Cf9J9Wkz/W9zV9of6o=; b=dE9jUS3d0sMXWZEjSa9souWDnh1tzv5zTQ4hj6JFMIBHkFhmGKtoVu4+/I77gQ9yDbSx0AbyJx0hyDKfekDoW5KwNkZMGemhTZ0LSWJyP/+KVzij8stoS6ih3PC+DQDsaOM7w96J2kGY3OKEH/Xw8rtz/Z1yLJ8/4zvRj+w5+sgXbJBw4xlP/0njUEJyOShM/OOY0hPrGQXEyR1hZK7yvoeuVPcNFeEU3vuhBTEAW/FjBWSzzYWtJXhPSSZZwFwjqaLgUHMxXNPi1LrnKfIANVvfY+/DHDe+cQKWT+bRONMhuLOIixZx+KQL0kQAtzFYlaoltf4rSI2XwLU1FqKUBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4mRwQKmzZq41ZR1xsbsETIF++Cf9J9Wkz/W9zV9of6o=; b=G75Ex/PaSee3h9PPXWhiFEtcLi0G6pT3PKrd8U7J1PJQWO6dYb+wHpNT5FkRjMYxUzUAXucE+CQI0NVIeszoH8nBYn+Q7eoBGcGggykzz9fudiHCgHMo3CUx5/7Ihtr5ar8MOqy/TvbbX5GcMsfzU/kuMK15Bj3Cv9SjRYgLAm4= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by BN0PR10MB5031.namprd10.prod.outlook.com (2603:10b6:408:117::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Fri, 18 Oct 2024 10:17:03 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%5]) with mapi id 15.20.8069.020; Fri, 18 Oct 2024 10:17:03 +0000 From: John Garry To: James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, colin.i.king@gmail.com, dan.carpenter@linaro.org, John Garry Subject: [PATCH] scsi: scsi_debug: Fix do_device_access() handling of unexpected SG copy length Date: Fri, 18 Oct 2024 10:16:55 +0000 Message-Id: <20241018101655.4207-1-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: BL1PR13CA0148.namprd13.prod.outlook.com (2603:10b6:208:2bb::33) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|BN0PR10MB5031:EE_ X-MS-Office365-Filtering-Correlation-Id: 03f00847-f79c-499a-bbe2-08dcef5e02d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: 5dgd1J41m8op9uh2aK2y3NpzCq8ZSV8a0wojbYLqJ1h19Tw3Ly9X5K8vQLHB+kPS4wy1vqBUtV4ehGPlHXF6TZ/H7XP1KcMIXf9baMJFbI4bfiLuquf7d8fjj2e3o8upyMj8gZpWyNUa0LOgzMnKBadrbzi9JERQ/sZsQpPeBdJ0sp/kYGfHAZiTsP5dKWxZ6Jgozhou84b4tOxiNcCKACMltgt8ETOb9+95XS772PJVw+qiKR4VlVsHZC9asFvquUitvhKsE/pnUYuiMXI5DYwsMFPCtK1yXVR0R5Fbs6b66eOitTKigjgOCTk45cAOPKzKYPYvr2V5MchvdOJjeTppNCJBVE6QGsoAEiiNsoGEHJqcXMm6E1Y4eJGXfohVjw5qVh5tLuqVLWdYBsiYO/AXMWy1mONVXhKtcN+AzwTArAq7IpvcFVFdb/nYYGP9Rv6hDZwmgxDJyT/m7Oy/b0KjK9+PFfbu+Q5O9idkaHZ63AHizhJs1vkStMmFN6I9IJN6sOdesJJ498Va0v3kIG/oUdqEbjwb8xERod9nVcUOOJhd5Ag94jVP9R37KBtcv2yTLjYSP9YuWOo3pV1MU3H+mBdKd+FS3X/sVwCICvzsZAnndGgk5XoBkLqqdcn97NC72xR8e5tYfsfJ7b3RtQdW8FMuSz3qS5rVZEJiW1pr8+AjAFFu/jK66ocsJOw6H7CNJMKAb/LkenTPcz0p/w1eiV0sJFHXoEHESnzTlV0zSeSA8flf9lZtZDJSPbkyR5qYbByXz6H52sJR1JWMnMQQDC8LuSX4waYGV3qHk8BU9bXTYe8HDXF+/2BhAEVZrQFi9kSMhbyIiYIdWwYAOnR7E49L4RfCjFhnRo0n9BwXs+JEWm2P3URT6t/lVGVEptRH954lx0QwI/tYnoauFDJGjhCqwm6RU7E+NKTFsixL9hIB2C6HQb4GeBF6HqkdDvkXekmuCY/kQSjVm8qi8oZQ0EdIGMXVNWpECAbFzEIVUOf2vjVPxbsn6aVbisBZPhwhgMkP1irnkYA5Qn23sl8v+D3DbTKZGMYEPZl/imRkV+VASYcCgbyB5uQWGITNu9PJ9nguQShv8OUsDOT4uuGhWLRPmcoAeV0j5jcWvRLZuGRIYyRpjlltWqzGYfQYdoEZ2AqnF0S+lswe9slYtVDxySg4o3y9dLP2Jex+UnUB5gLth2fm8xRLME6Z3AFRJVFth0VsHs7eoOJHyH0UuPLTIlvlbYH0ua33BFL2oJmGDxuJgGxuoB+R/c/BLqiFmt94nPG5H/Be8ghCl8tt6IAJ5qMfZKh5T0YJIoxSwvxAS8W0fcpD6mGDBHKv7A0z X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EcKX/LPZsm6vR4Fs/P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myaienz1CdsVxxgq/2dX+6w1Zn9y/YcouXIZdPOBV/658u/dwn+Rfi5JHiwDyZnqh2vAcO4pZI+b2rm6YFwRt2b6CuXOzalSLT3BwRSxKZqx4m4x31DL25q+U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03f00847-f79c-499a-bbe2-08dcef5e02d3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2024 10:17:03.4485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: aF05Rsw/QQiGszVnJ865fB/atu4gyYexyOlxSPZqPQSGo4qTk1+R5nrgff0TibM4klN4OqwdHnUF5BWSsz52bg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5031 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-18_06,2024-10-17_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 bulkscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410180065 X-Proofpoint-ORIG-GUID: wIOV6ES_v5OROTe1K0BG1jabDT-L-Qs7 X-Proofpoint-GUID: wIOV6ES_v5OROTe1K0BG1jabDT-L-Qs7 If the sg_copy_buffer() call returns less than sdebug_sector_size, then we drop out of the copy loop. However, we still report that we copied the full expected amount, which is not proper. Fix by keeping a running total and return that value. Fixes: 84f3a3c01d70 ("scsi: scsi_debug: Atomic write support") Reported-by: Colin Ian King Suggested-by: Dan Carpenter Signed-off-by: John Garry Reviewed-by: Dan Carpenter Reviewed-by: Colin Ian King diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index d95f417e24c0..9be2a6a00530 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3651,7 +3651,7 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, enum dma_data_direction dir; struct scsi_data_buffer *sdb = &scp->sdb; u8 *fsp; - int i; + int i, total = 0; /* * Even though reads are inherently atomic (in this driver), we expect @@ -3688,18 +3688,16 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, fsp + (block * sdebug_sector_size), sdebug_sector_size, sg_skip, do_write); sdeb_data_sector_unlock(sip, do_write); - if (ret != sdebug_sector_size) { - ret += (i * sdebug_sector_size); + total += ret; + if (ret != sdebug_sector_size) break; - } sg_skip += sdebug_sector_size; if (++block >= sdebug_store_sectors) block = 0; } - ret = num * sdebug_sector_size; sdeb_data_unlock(sip, atomic); - return ret; + return total; } /* Returns number of bytes copied or -1 if error. */