Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp232799ybb; Tue, 14 Apr 2020 23:52:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJRfeSVOQYCjkHmVxCmfgzywQI45TyeZOr8zJ+A0tplysWgSm+Wi9JMbhkDcaMRTB6ipjtO X-Received: by 2002:a50:dac9:: with SMTP id s9mr21430964edj.313.1586933532659; Tue, 14 Apr 2020 23:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586933532; cv=none; d=google.com; s=arc-20160816; b=RmlRt/bacIUyHBsdFB8ntzvqp8EATs8/Vh/5QhV72J4sS2x/fEICVY6fA1X9gBfFsU TEo7ceTs2KKN/qftobFp7xp5IWZlrSV6Zi9t1I3HE9tdgxUhCAoDzlgILKIfcH9kKqCl UJjrJRK2uFGduOyOkQBY88SA5R2J2set/gfrjkGG2ncXS+J6q+iJq9hX7C5ouDBWLeUR resnV/J5iJj4viorf/OjotnAtxhP0SXw1ycLr3Iw7izf5EsSH/wdbG3sQv7REl9IlUK9 97o1xx4b24Nqb0knYv2UXode9j3BE31ufGdbNeZacWB38m2uqKAWm7tb16H2iMGKxaW+ IoYw== 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 :content-language:mime-version:user-agent:date:message-id:subject :from:to; bh=IkDDlx0VgMAtChD/P1QlMH0lhYRpLMYshmWlNYPxeMM=; b=K7KZD1lvb8ExBbKUNhvv6aIjq06quB/KX7lCCGbG4SKJ6co/8d5JKUqR3enu1E4Hiz azj/Ut1zQ1RSkyN0cw5ozY4SMenDzHcbZWi7PWFS2HF3L5APTS6i1VBfyL9t+ylq2ire T0YWuFkSUZrblQz0EQox7ECK5mNnnUauDOQIPyzYzkNSL3GKsBMUdOa06bzhkybKeWXt FmO+6uojYt5eTWCUo8UXnN/+/A/bnMqjWnk4If9rmXROwbY+xYi7J0CitgOum1O5yuAB 86+fwN1/QYU0J9koQ8w4NJNg4PdYgM9bpOiNhu/YQebZaDrnhY/eVFcXA5sx/2BHOMul qLuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m11si1886920edq.373.2020.04.14.23.51.49; Tue, 14 Apr 2020 23:52:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404001AbgDNCNp (ORCPT + 99 others); Mon, 13 Apr 2020 22:13:45 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2367 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403967AbgDNCNl (ORCPT ); Mon, 13 Apr 2020 22:13:41 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A6650673AB8245D8F5B5; Tue, 14 Apr 2020 10:13:37 +0800 (CST) Received: from [127.0.0.1] (10.173.221.252) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Tue, 14 Apr 2020 10:13:29 +0800 To: Doug Gilbert , "James E.J. Bottomley" , "Martin K. Petersen" , , , , From: Wu Bo Subject: [PATCH] scsi:sg: add sg_remove_request in sg_write Message-ID: <610618d9-e983-fd56-ed0f-639428343af7@huawei.com> Date: Tue, 14 Apr 2020 10:13:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.221.252] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wu Bo If the __copy_from_user function return failed, it should call sg_remove_request in sg_write. Signed-off-by: Wu Bo --- drivers/scsi/sg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 4e6af59..ff3f532 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -685,8 +685,10 @@ static int get_sg_io_pack_id(int *pack_id, void __user *buf, size_t count) hp->flags = input_size; /* structure abuse ... */ hp->pack_id = old_hdr.pack_id; hp->usr_ptr = NULL; - if (copy_from_user(cmnd, buf, cmd_size)) + if (copy_from_user(cmnd, buf, cmd_size)) { + sg_remove_request(sfp, srp); return -EFAULT; + } /* * SG_DXFER_TO_FROM_DEV is functionally equivalent to SG_DXFER_FROM_DEV, * but is is possible that the app intended SG_DXFER_TO_DEV, because there -- 1.8.3.1