From patchwork Tue May 23 23:48:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9744483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8A6D16037F for ; Tue, 23 May 2017 23:50:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CC9128818 for ; Tue, 23 May 2017 23:50:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 713CF2885B; Tue, 23 May 2017 23:50:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C219628818 for ; Tue, 23 May 2017 23:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032054AbdEWXuD (ORCPT ); Tue, 23 May 2017 19:50:03 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:63550 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031237AbdEWXtm (ORCPT ); Tue, 23 May 2017 19:49:42 -0400 X-IronPort-AV: E=Sophos;i="5.38,383,1491235200"; d="scan'208";a="21079239" Received: from mail-cys01nam02lp0053.outbound.protection.outlook.com (HELO NAM02-CY1-obe.outbound.protection.outlook.com) ([207.46.163.53]) by ob1.hgst.iphmx.com with ESMTP; 24 May 2017 07:49:10 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=+On4Zxh46z27Q9QqkUYw9H3c5rQ8z5giSCSUUtmf5J0=; b=VBY9QfkIsAaqpfz/T7JQlSqMvlr7x6lzb4BzJsmMiiakUtEVJjfNI9z3A3KKN9iBk9/qvQ07RIoVJfPK6Kt3eAXOR6Wu7pQzGoz/sTqW/tz2CAu7hqKdYyCqu+YA8bp6fUQPsoXff0Uo52gGwX72Gq4qq05/VocRbzPggH3iNmU= Received: from BN6PR04CA0016.namprd04.prod.outlook.com (10.172.194.26) by BN6PR04MB0355.namprd04.prod.outlook.com (10.173.198.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Tue, 23 May 2017 23:49:07 +0000 Received: from BN3NAM04FT005.eop-NAM04.prod.protection.outlook.com (2a01:111:f400:7e4e::208) by BN6PR04CA0016.outlook.office365.com (2603:10b6:404:cb::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9 via Frontend Transport; Tue, 23 May 2017 23:49:07 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.21) smtp.mailfrom=sandisk.com; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.21 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.21; helo=milsmgep15.sandisk.com; Received: from milsmgep15.sandisk.com (63.163.107.21) by BN3NAM04FT005.mail.protection.outlook.com (10.152.92.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1075.5 via Frontend Transport; Tue, 23 May 2017 23:49:06 +0000 Received: from MILHUBIP04.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) by (Symantec Messaging Gateway) with SMTP id CB.D1.45291.07AC4295; Tue, 23 May 2017 16:49:04 -0700 (PDT) Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.319.2; Tue, 23 May 2017 16:48:59 -0700 X-AuditID: 0ac94369-166ac9800001b0eb-08-5924ca700900 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 72.03.18148.A6AC4295; Tue, 23 May 2017 16:48:58 -0700 (PDT) From: Bart Van Assche To: Nicholas Bellinger CC: , Bart Van Assche , Hannes Reinecke , "Christoph Hellwig" , Andy Grover , David Disseldorp Subject: [PATCH 26/33] target/iscsi: Make iscsit_map_iovec() more robust Date: Tue, 23 May 2017 16:48:47 -0700 Message-ID: <20170523234854.21452-27-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170523234854.21452-1-bart.vanassche@sandisk.com> References: <20170523234854.21452-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRmVeSWpSXmKPExsXCddJ5kW7BKZVIg7/tYhb7Zz1jsvj6fzqL xYI3e9ksVq4+ymTRtvoMo0Xr0rdMDmwe97cfYfLYfbOBzeP9vqtsHuu3XGXx2Hy62uPzJrkA tigum5TUnMyy1CJ9uwSujMXTVzMXbNCp+Lj3KEsDY6dKFyMHh4SAicTL7cJdjFwcQgIHGCVm v+hnhnC2MUqserOasYuRE6zo5893rCC2kMBGRolvp3hBbDYBI4lv72eygNgiAjoSs+6+YAdp Zha4zSix5vFqNpCEsICHxMFrb8GKWARUJXacXQg2lFfAQaLx82moBfISZ7fsZAaxOYHiK/ds Ywa5TkjAXuLyd2WQmRICy1gl5t2fywTRKyhxcuYTsJnMAhISB1+8YIY4Tl3i5JL5TBMYhWYh KZuFpGwBI9MqRrHczJzi3PTUAkNTveLEvJTM4my95PzcTYyQ8M/cwXj3ifchRgEORiUe3gQH lUgh1sSy4srcQ4wSHMxKIrzLNwCFeFMSK6tSi/Lji0pzUosPMUpzsCiJ856TmRohJJCeWJKa nZpakFoEk2Xi4JRqYDxn3/9zK4fyszaXL81fy34vUZmomBXOEbztuNwO49BJ/h/efzaVXJ2+ J1uu+Kcwa8/ai5OkNqyQn/n14f/2323x0Vs3zFu1lY05L++bdOGRnT1zUtX2vv89d8PX/I5Z NR+vzf3x/drmmz1spV5Sn2JOzCl0Y7/T6VHAuNB9csfsj38WNE85sodRiaU4I9FQi7moOBEA OQ/VynsCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBJMWRmVeSWpSXmKPExsXCtZGTTTfrlEqkwZI+C4v9s54xWRz82cZo 8fX/dBaLBW/2slmsXH2UyaJt9RlGi9alb5kc2D3ubz/C5LH7ZgObx/t9V9k8pq05z+SxfstV Fo/Np6s9Pm+SC2CP4rJJSc3JLEst0rdL4MpYPH01c8EGnYqPe4+yNDB2qnQxcnJICJhI/Pz5 jrWLkYtDSGA9o8T73YtZQBJsAkYS397PBLNFBHQkZt19wQ5SxCxwl1HiTPcnNpCEsICHxMFr b8GKWARUJXacXcjYxcjBwSvgIDH1jjPEAnmJs1t2MoPYnEDhlXu2MYOUCAnYS1z+rjyBkXsB I8MqRrHczJzi3PTMAkMjveLEvJTM4my95PzcTYyQsInawXh9ovkhRiYOTqkGRsudbY/5bP0W 6u7+F/SM4duy9JXvsnMKzMy2Fj+68Sny/euWtRe5dt/f7LSwbuGxRymtrrFaajn6btuE7Ltd VTzNLfKL998wmRP6gOmm/M/czasVwhy2MnDOnZI85SePX+GnszWPbr68dI5nw7qzt491zpfk WXZzm+Pt//zHdu7csPz2jc48iSAlluKMREMt5qLiRAChgyxkywEAAA== MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:63.163.107.21; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(39840400002)(39860400002)(39450400003)(39410400002)(39850400002)(39400400002)(2980300002)(438002)(199003)(189002)(9170700003)(305945005)(72206003)(33646002)(356003)(1076002)(106466001)(8936002)(86362001)(50466002)(50226002)(36756003)(48376002)(189998001)(76176999)(38730400002)(50986999)(110136004)(5660300001)(77096006)(4326008)(478600001)(47776003)(2906002)(6666003)(6916009)(5003940100001)(81166006)(2950100002)(53936002)(8676002)(54906002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR04MB0355; H:milsmgep15.sandisk.com; FPR:; SPF:Pass; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN3NAM04FT005; 1:DGPzGn1nG1MsCmMlsu47n9x8FtDE8seCWznciEYrZl5OTcX5b5CGQPukbe8upZ2Ok8nfHOjfejUqEmKBHBr/B7yh68IpKwIOYndB2MX6NYUD4O81GYj8hQVEGkHEKFlopasS69N6hAZSMjUCCq/pvdadbfFM9yQlkQ9GiqIRN1P62SMoPBPtMqVsUB4Wu3Uyyylz3bVbD5TYSQqUEf3ZL+JBTjIXrZ9PcQGC2ccVh789SEy+lWsIZ5jHZ/xdrkCra227dnMESL8q4TI48me9KSTW0yaXQ9Hl7fSqj8SK4mRRi752ZqjnH7Dd6Rsbj2k88+W3Cnm7Ew/vYYqV/2nyENBf5KHMlqnypNfsACVpA0FoQxQBgL17VBuodLwewytldxDKJed7iaZajtVa/4Ljx6ZbGgoGxrL1di/zHYo1EdhK9apbcqS2mT2zngdbl/WadRGqzBELSRaZ56PtoZpqxwPzCKzxDdMHRjAkGYMJHMmttBm53m4Y5lVDBCXNZzpxzFEaCXmeIpoMmf5e5phdZihflIyluR+ACRKysTQ8Jqk= X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN6PR04MB0355: X-MS-Office365-Filtering-Correlation-Id: b81c48d3-f88b-4966-0258-08d4a2364d06 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(8251501002)(2017030254075)(201703131423075)(201703031133081)(201702281549075); SRVR:BN6PR04MB0355; X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB0355; 3:dXHTlhw4ka7hNo4aR86hh42r2KYNq6Hsm3X/ccAAazayR8CQXPp8SmFnkKizPjiGRbDJy+dAj+UyBouzmPlheL6ACn6Ga4Hmn5aisRYQoO0r//Ezz5gdH87kRdFW6UTHzEnAf7imR62Pv8s8kQMS+RY4xwYvF6dFlRdSveF8Sjv4JLLG78J/pNcP8enupCkSifLdXTe28lBFkNFUtP6PtsmWqJyJvc9lbtxLKnIi7yk8nqIrqWBpAPrrxxLVz7jYszCYYgLIcDUW4M+nsdHFn5CLet1UlrWNFT+GHctkXaSJeID0WEgxSvUU1CImG5NeJoPhSzLtq9VrPsX5Zj+Plo6IlkoCa4q3Bg0geoEPLH8yLK0tmFxjxIDjNX0DllufWTokGjV8dgbdtXNT8OeTGlfgZgaB9obDeMus/hMSfUcvNozo8nHONJU/iu/M70zjEpyP1x2uD0P2SbdR1q7f2ux7RfPClFo6xkO2/arYts9/bX/ZwQgyYoWeDyXqT5ceD8VsvixuwRtTNR8eQvaeXw== X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB0355; 25:2dgrqFLlB4iYn6eHoTUqbUcg5XQipUaApNvX5f3jvvWvI+QFm/n+SSkB4wosGWZxtS6gKAQKSTZ/wstV25USADqxFevCZJljyF4K06/8v2r5zDKXEjd8e5j0QWJKcm3WdT4BHC8dAS563XCS2pPxKVvEjHQszdiDxwZqLBf3S8BcEMih81CIbMhqhPQSDUA38DC0xRQeKftN8Yebf87klqwJEzSZ0gNtpTdk3zdzRZVhu/gp2VZc7ww3CDgeasFqloVarpa7zmjuAAg1OOvxws8YZv4EaCLUSk3BvXN2w7ApP2jPjGJIzgRkMy1GiAUBfBjJ8u3Mz/ZrYYX4m5A7dKiZcrZaCak2sbWd2S0/VpgqEo1HSIQj3LdNAXFpCvaj4KurBk436XovskFBpwVim56k9tPEYbVbJk7JM0tweloP9oTqLyIMcrBYiQPoHo/zkKrVbm+T0hpw3dpvrXN+JT0VJ9ptBHS00p/WV9SHzdc=; 31:k2En7todikYOuh/jucomms+2tFjVhCXzYnXwzjAj6lP0tLogTPPFLKoOX517x+Kob50CZUFCe40d0H8Arar7t5xJ4pPy0D2+Kk+rt6cjgXWwrAgddVrLnaFVRN+EXDV7ePQ4XiA9Q7RU0dgqbaYdXumYjW/O8mJuslCQvLIwoxxSNzaiEK9EtFkJTR1X9w2lMUmnSIWZStaKbma8liGpbJQ72NXymT4SSq4M7+hkw8ssP5U/hwXPGqt0S4pc6C2AkMhTNtp/f+aMDqIfibO6hg== WDCIPOUTBOUND: EOP-TRUE X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB0355; 20:Ld5Y2FnbGyxvHUfl3AftBpeIMD1999oUayMrW3zYgyLjPWtSd8WV/ovrr2Pvf0bccJ31c+jQ1QNS7SgAl54DeZ/jujuu1g6fThuEwyNHsbsj+mTAdIljQC2JrlEpPZBF52UIYQyWOXNT7Z3SnWZVv8CTGlm2JXyXVEENWGMN2Mpnd4xvdGZO+Ra7z+RwFwIblQLHiUgO/KnnEWtD7X97y2hmTpke9x2GB8TwwsxJ8VwtOcNk0zYcqS/8U///ZbEz+ndEGvElI5DlKlO+lHguF1HPDUewwCrU1H0+KyeSa7J4uvV6NZCFUgoEBIvGzay/DxhmMODXZ41Ak+GQt7GLT5VTt+sSDoi2W7frcfeanRCYKtnoFDva5wKUqZZaORXmi0rrVirmz7L3Lyxn6mpR60FCKReoDm6kp+fovuUGoDvoAINKFGYcB2Gln1aqpl1T1eTtvPgKiZb6IRRRC8gvZCGqIiD+SL5BiSoLAoif6DwhP5C3Ecu71vepIpAvoyZK X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(13016025)(8121501046)(13018025)(93006095)(93004095)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123560025)(20161123564025)(6072148); SRVR:BN6PR04MB0355; BCL:0; PCL:0; RULEID:; SRVR:BN6PR04MB0355; X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB0355; 4:xxR02/PrhQOoZu+fef4NyIbfqeJQwr/I64Ms5dFos/KMWcfR7FGTMpv410JYQ9wnO0uaKDo9efQS9DVqUy0TzauVETlxEWumw/6Z/5knzDP67M9Ii8qy98fjY0eEMWDTq1NPqPvXfbwT4VuQbG/OgTnKPnf/zwqHifwCPmUG8tkuxL+aa4Fzs8olVshhqWovTQzLXBlkkHkt49IP4QwSV3ezqdBG7Kyjm0yGj4731rNsOLYlGRM2AmEVfeD29FXorgCUX0RrXQRvElqoUK/F3T1zkqRhGrZIIrfxqqjOv5a2i0Z1VeRSXA56gfKt0eL5eKN4Yi12ke0GAs8BUDQH/ddG/R976OB9jYn82Vn3lFSA2sieq2X6nI1kTXK9zqvtsX84ioX4CzJlc5/DjGWnzTlfUfoKB80g5K+vN9ixNJ8Me1KtI2y/nAN2DwyhF+sq2hLonX9B5HYbzG/5dHYkXCDEAjJ7RSwwbjDq/F73lHAhC0UDhuAWE4Il19deAJU5+MUBGZcqliXanPXZI+ARG53zLrnN58QPKp4p+gob3iMRQL6Yt4/L+U4vg85oDwFNkQchtsAytjtQAE4aSJduFgMwH6wcHFRmsO6cXC7QTBBjokJ7We85t3yQqgUmqlvNbKIro8pcE3y7BkVZMowwRI0Cp8E+fhzpf/WtGQNXnTwOhWDh9BzZigFKsUgCrRJ3hRnYAITkZ7vIZlkXkzoFLcRg9rm+/1mHS4UHAbjTJQ1BduGwl7h5U9jpvy7+Y+NEjSyVe+jYNeucd6zM8RTeHPqZULb8JNoY5Dp+k1Q6kK7KcaDm4viJ6G3rV/Jlp/ULJldIFs2RAbjWZK3W74GxpNZUFDTB4u7Ndzp64YYPPYssDc8P0Lq2nXPS7F1oJOy6 X-Forefront-PRVS: 0316567485 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR04MB0355; 23:LCTV4JduFVElQSealk/2gSeUTGfsdr5Uyrv04TP/H?= =?us-ascii?Q?rqSCUZ9JcKLQzD7fKoiiyvuhq/wcNinvF1/VcpNupOI2S0fXyTJi6h2Ls7GI?= =?us-ascii?Q?1m+fA7hHTqpDMh5HN5zCdsn3lWthKBtpOQ7lEql9z94SCqi5409GFY7SIVCT?= =?us-ascii?Q?hixdhrEFUUpM3pTQGKPZjaRU2kOl2ZoWH05SqZvoblXd/CYVK6Y0L2s1m1DU?= =?us-ascii?Q?Xhlw9Fmctod4SsrByIw0tTA25RzhUAZZsDyHLKxnDfOtFPwtOVxQfuHYKs3j?= =?us-ascii?Q?PksoxBkwqI0iVphgHOXE4c3pYeHpx5wrgq429ECa4cGfHeNgRkamJThTo1SO?= =?us-ascii?Q?Xb1njhQDurKi4D6TOK+R7CzBJ1YBbxz8MTtK00SZhGZs0pS3kX68pEhhH8Zi?= =?us-ascii?Q?DZ5PYl3tvBKOfGf0Ob6DOMyaw8urArRrlDNtbM3Mtl951V4xSTmj6Yr3R1FX?= =?us-ascii?Q?QJPXLTQ7ykpINOf05YM9JjHkQ1jLmaio1tSt4XasR/wIt2n9cK/F2i9Vns7n?= =?us-ascii?Q?R0lutB7PvGOPesOyTT9F34XYHFXL944ckq+GmcAsuold14en6whN+lsNY70k?= =?us-ascii?Q?qtnrKldWseaImWU+LqFcKLRlbzDSKqBSm2o8rmpVGqK7LRTkMBkUk3Cr0kD3?= =?us-ascii?Q?ABiKsimfqhOozOzyzHE0F0Pq8XzcK11dOQDFMrHmPDtxR5XtLohcidLkO1Xt?= =?us-ascii?Q?+QMMRu14aPJYLJ2XqgDwddyDFi6pTc24hYy6bmJnDXOh/Ak96pwYdUOspBBu?= =?us-ascii?Q?DrLh9amqw0h+lpUUQFNv/LTReKHc97zhKNyI00At0rbnAGFA6xPQFXLh/e5H?= =?us-ascii?Q?tfHCSwnVkXUK3hz898RP2/JM8XzBlDmrUxjgR6Fh9Z6YhXWGI/2zzGrn+B4j?= =?us-ascii?Q?HgW1zFxoXA2i8G3fsJVg2YC5P5uxqiZ9o3kv8V4Z5ncalL0CXWpzsxUtu7dI?= =?us-ascii?Q?qnJi85u6PVQlm63/2YJ6tiELpsBCPrgiGI5yrP06+eQI/aP4NELJPhAM99QK?= =?us-ascii?Q?nrz19q02JF882bs2lCyBqCO+kmFVGI+OX7vsvD91Fu44pSzkx99r8yVc+let?= =?us-ascii?Q?j/CQJ2UGJ/WbHhyFNE9WlMiAEtOwlLu8e6EGTmkaVvgk4WGnw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB0355; 6:WaAuAzdMEO54hUt0dGLB95bS+Hi/kHCD1w0rmqT1treRV7Io/7cfEzasM9HBMUBPZRy8D/Gt1n4KxuMA1XDF74id76dfg3VmN3zAWJiixIAAuzdsLapRG5THgJgwP4IscT79vQl6BxwMNicS6O0BkBIVPJvbTTrvCswAQ0WrEvqXHTuoebLLi+uuIMVQkQflX8XsiuNFpX9YnLUNBKTaP7c3Vzmx4Tl1e9/Y38IeefP+xKyiq/yvCU27R4j1pYIUho10gAJh8TY4M6ZvdyxgeQEnhtmLxi5uyxWVR7cYjZFQwGgGqb8v8rHwibvpo98j7fSOsY3pTzIFux7k7g8x5AeKak35MffF+0nSDF+7/NeoN/6Ox2yfjUZAK61PjutbdUgFvXeYDN7N75l2T19Ui00wXUSA8EmQmQtaiLxvbJBrF07OsHDxJOBR5Erv6O6ZdDN0UPQagFduFNsjI05CC9arx98MCBTaIn6nlQVruDt/QeDSSR0Oodth+f5VnjYRka1Uh88F7TbSTxnfxN//BZlUUd3miX3gdPmvnUVkce8=; 5:9P0HQjQfKCTZ5SqHYrop47c3E51zAVgtQDAkckBk/X/lfq+Y/6pRcdiuV5U/UgBoM8BPzXSJRQCjAsyEVNz00h3HubCBLo4zmp7ISfq4AUW/gV0cNauUCgdimmMebyziSgfhqEYl2gkRlRL7Mw5jyA==; 24:2xpem77FuHagxMsQqdXbQnzNMPSdUvwJj9E1wDh1ctIh4dPCszUwaW3GRNX72A7gh2HDHz6t0tFyLTq7e3hOMQxa/ilg/Ages6YoZbuNLKQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB0355; 7:Y+Ak1E9tUz5vVcyb4GENbq9lkEUyhvBc747jafmFzuWs1sWy1ON0bivws+ot5qoFtqkjOoGGM+yHbbsTpBKJXId4cvmME88EQyOdpPUv8JwB206RCi3IrxL1x6wjwF5jtRlY0833LPDTlxYp6sF8diV5ERtT8//P1XSjaoJ5lV4kOO/0Is+0epgyZdC5aceitVO6MCmN6T3S3Boxa6pGShtMC+IcUsac9aWBWgCHWJRmF7JhBkmMSaB9ur1u4m8hIk2BTN0kgmB2GLiHREiTGegQr20v/ncfAHTn97q/TG8VY0pSJ4sdeeGZI2FskV4kKkAEdKmoOqfhSVj8Fp/7zQ==; 20:hiZEA/dtPXjTi6pLPoR/jiWfsMJb3PLPBJJhO1CDd9nWXAALCqAHRrCapKSfcdFWUhmI0l/HZJ5rp8wz5+0AZfbBu2qihRlFJxjkP7Fzu3AEvNmcWYVmy1vkXH5vVq1aOriLlcL3mpbFLbYeYicwxIrmiSuc1gK3BOey9R+UK/0= X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2017 23:49:06.3224 (UTC) X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=b61c8803-16f3-4c35-9b17-6f65f441df86; Ip=[63.163.107.21]; Helo=[milsmgep15.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR04MB0355 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the code for mapping an iovec more robust by checking the bounds of the allocated iovec. This patch avoids that the following crash occurs if a map attempt is made that exceeds the bounds of the iovec that is being mapped: BUG: unable to handle kernel NULL pointer dereference at 00000000 00000014 RIP: 0010:iscsit_map_iovec+0x120/0x190 [iscsi_target_mod] Call Trace: iscsit_get_rx_pdu+0x8a2/0xe00 [iscsi_target_mod] iscsi_target_rx_thread+0x6e/0xa0 [iscsi_target_mod] kthread+0x109/0x140 Signed-off-by: Bart Van Assche Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: David Disseldorp --- drivers/target/iscsi/iscsi_target.c | 50 ++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index c91604feca18..9e09e1905869 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -572,7 +572,8 @@ iscsit_xmit_nondatain_pdu(struct iscsi_conn *conn, struct iscsi_cmd *cmd, return 0; } -static int iscsit_map_iovec(struct iscsi_cmd *, struct kvec *, u32, u32); +static int iscsit_map_iovec(struct iscsi_cmd *cmd, struct kvec *iov, int nvec, + u32 data_offset, u32 data_length); static void iscsit_unmap_iovec(struct iscsi_cmd *); static u32 iscsit_do_crypto_hash_sg(struct ahash_request *, struct iscsi_cmd *, u32, u32, u32, u8 *); @@ -603,7 +604,8 @@ iscsit_xmit_datain_pdu(struct iscsi_conn *conn, struct iscsi_cmd *cmd, *header_digest); } - iov_ret = iscsit_map_iovec(cmd, &cmd->iov_data[1], + iov_ret = iscsit_map_iovec(cmd, &cmd->iov_data[iov_count], + cmd->orig_iov_data_count - (iov_count + 2), datain->offset, datain->length); if (iov_ret < 0) return -1; @@ -886,13 +888,10 @@ EXPORT_SYMBOL(iscsit_reject_cmd); * Map some portion of the allocated scatterlist to an iovec, suitable for * kernel sockets to copy data in/out. */ -static int iscsit_map_iovec( - struct iscsi_cmd *cmd, - struct kvec *iov, - u32 data_offset, - u32 data_length) +static int iscsit_map_iovec(struct iscsi_cmd *cmd, struct kvec *iov, int nvec, + u32 data_offset, u32 data_length) { - u32 i = 0; + u32 i = 0, orig_data_length = data_length; struct scatterlist *sg; unsigned int page_off; @@ -901,9 +900,12 @@ static int iscsit_map_iovec( */ u32 ent = data_offset / PAGE_SIZE; + if (!data_length) + return 0; + if (ent >= cmd->se_cmd.t_data_nents) { pr_err("Initial page entry out-of-bounds\n"); - return -1; + goto overflow; } sg = &cmd->se_cmd.t_data_sg[ent]; @@ -913,7 +915,12 @@ static int iscsit_map_iovec( cmd->first_data_sg_off = page_off; while (data_length) { - u32 cur_len = min_t(u32, data_length, sg->length - page_off); + u32 cur_len; + + if (WARN_ON_ONCE(!sg || i >= nvec)) + goto overflow; + + cur_len = min_t(u32, data_length, sg->length - page_off); iov[i].iov_base = kmap(sg_page(sg)) + sg->offset + page_off; iov[i].iov_len = cur_len; @@ -927,6 +934,16 @@ static int iscsit_map_iovec( cmd->kmapped_nents = i; return i; + +overflow: + pr_err("offset %d + length %d overflow; %d/%d; sg-list:\n", + data_offset, orig_data_length, i, nvec); + for_each_sg(cmd->se_cmd.t_data_sg, sg, + cmd->se_cmd.t_data_nents, i) { + pr_err("[%d] off %d len %d\n", + i, sg->offset, sg->length); + } + return -1; } static void iscsit_unmap_iovec(struct iscsi_cmd *cmd) @@ -1572,8 +1589,8 @@ iscsit_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, rx_size += payload_length; iov = &cmd->iov_data[0]; - iov_ret = iscsit_map_iovec(cmd, iov, be32_to_cpu(hdr->offset), - payload_length); + iov_ret = iscsit_map_iovec(cmd, iov, cmd->orig_iov_data_count - 2, + be32_to_cpu(hdr->offset), payload_length); if (iov_ret < 0) return -1; @@ -1593,6 +1610,7 @@ iscsit_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, rx_size += ISCSI_CRC_LEN; } + WARN_ON_ONCE(iov_count > cmd->orig_iov_data_count); rx_got = rx_data(conn, &cmd->iov_data[0], iov_count, rx_size); iscsit_unmap_iovec(cmd); @@ -1858,6 +1876,7 @@ static int iscsit_handle_nop_out(struct iscsi_conn *conn, struct iscsi_cmd *cmd, rx_size += ISCSI_CRC_LEN; } + WARN_ON_ONCE(niov > ARRAY_SIZE(cmd->iov_misc)); rx_got = rx_data(conn, &cmd->iov_misc[0], niov, rx_size); if (rx_got != rx_size) { ret = -1; @@ -2268,6 +2287,7 @@ iscsit_handle_text_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, rx_size += ISCSI_CRC_LEN; } + WARN_ON_ONCE(niov > ARRAY_SIZE(iov)); rx_got = rx_data(conn, &iov[0], niov, rx_size); if (rx_got != rx_size) goto reject; @@ -2583,8 +2603,9 @@ static int iscsit_handle_immediate_data( BUG_ON(cmd->write_data_done > cmd->se_cmd.data_length); rx_size = min(cmd->se_cmd.data_length - cmd->write_data_done, length); - iov_ret = iscsit_map_iovec(cmd, cmd->iov_data, cmd->write_data_done, - rx_size); + iov_ret = iscsit_map_iovec(cmd, cmd->iov_data, + cmd->orig_iov_data_count - 2, + cmd->write_data_done, rx_size); if (iov_ret < 0) return IMMEDIATE_DATA_CANNOT_RECOVER; @@ -2620,6 +2641,7 @@ static int iscsit_handle_immediate_data( rx_size += ISCSI_CRC_LEN; } + WARN_ON_ONCE(iov_count > cmd->orig_iov_data_count); rx_got = rx_data(conn, &cmd->iov_data[0], iov_count, rx_size); iscsit_unmap_iovec(cmd);