Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3691246pxb; Mon, 1 Nov 2021 18:59:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrcXvMef5l1nIlXHzESeGN2XeKNaSvPKJ7WioADWu9j5M6BDFC+Q2xh/nusEPkbmOouOPK X-Received: by 2002:aa7:c044:: with SMTP id k4mr19911532edo.369.1635818349834; Mon, 01 Nov 2021 18:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635818349; cv=none; d=google.com; s=arc-20160816; b=QxdNhaG/P234zkLbgRfLibLwE/iPWgXKeyu3EzKpPGXub5ABiA2fRhms2joJhWFz9l kc9R0yTvtzkOpgV4ezNbx8kwkClY0iPjiCz95mCwBcehcenKxyxeYWVvbFbG12vaaCuQ u7fzCyePqD1Tyu01+WIyPgVSx5VgHkNMYigxRfFvrVvASxlMTIHZfzAqbGQJ5gObWA50 7cvo/4jNQM+PBVlhNrDbdWy0TcV+mBvKwwxcEL14fMZYSnzFCx0BJuJEW+gA4d+4xGxS zfNF3EWk0rdnUBcUyTTq1zuijmhHMLcC2UzxB6KQTRvyRt8cfyVnVQ42nmW6pg7D30Ou 195w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:reply-to; bh=Sny/MnBWKHoFPx76yBmSsvb+R8eROskYREVPKFpUhsk=; b=krmrsUVeJWSpKIPy7VpLHT8kGES6fKa/rQpqk/nlMkh0hh4B/ErqMyNmso5DxrIEmL yaXDWVQxPkVmesJjA0UBKxy/zpwZ+DMyfqeR9S82oaQQJM+4hAUvtfko3bIzB/6M5dWh sIBOVcCNyDBniUayFVXMBTeOCaJxODXSGenBON3dnV4QZxTT99V/3FMLtF4zJmy5dFWZ NDp+9z2e1n26bIZuSe+836u7PPfc/vrwnQhH9dsDU2ZKtz6nBx8QGpaTkYlbnwx1T28x x+hrZ0qOqogZZBo9n5BU6qb09uhuPcaMAtAOPcUhzN+wVu3Q/W6VRZKHTk+z3rKqxIq1 BgHQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si35140120edw.95.2021.11.01.18.58.44; Mon, 01 Nov 2021 18:59:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbhKBB6h (ORCPT + 99 others); Mon, 1 Nov 2021 21:58:37 -0400 Received: from mail-1.ca.inter.net ([208.85.220.69]:46492 "EHLO mail-1.ca.inter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbhKBB6g (ORCPT ); Mon, 1 Nov 2021 21:58:36 -0400 Received: from mp-mx11.ca.inter.net (mp-mx11.ca.inter.net [208.85.217.19]) by mail-1.ca.inter.net (Postfix) with ESMTP id 26CC92EA40E; Mon, 1 Nov 2021 21:56:01 -0400 (EDT) Received: from mail-1.ca.inter.net ([208.85.220.69]) by mp-mx11.ca.inter.net (mp-mx11.ca.inter.net [208.85.217.19]) (amavisd-new, port 10024) with ESMTP id YUyp_3wp9qgl; Mon, 1 Nov 2021 21:56:00 -0400 (EDT) Received: from [192.168.48.23] (host-45-58-208-241.dyn.295.ca [45.58.208.241]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: dgilbert@interlog.com) by mail-1.ca.inter.net (Postfix) with ESMTPSA id 6E7532EA0BD; Mon, 1 Nov 2021 21:56:00 -0400 (EDT) Reply-To: dgilbert@interlog.com Subject: Re: [PATCH] scsi: core: initialize cmd->cmnd before it is used To: Bart Van Assche , Tadeusz Struk , linux-scsi@vger.kernel.org Cc: Christoph Hellwig , "James E . J . Bottomley" , "Martin K . Petersen" , linux-kernel@vger.kernel.org, stable@vger.kernel.org, syzbot+5516b30f5401d4dcbcae@syzkaller.appspotmail.com References: <20211101192417.324799-1-tadeusz.struk@linaro.org> <4cfa4049-aae5-51db-4ad2-b4c9db996525@acm.org> <0024e0e1-589c-e2cd-2468-f4af8ec1cb95@linaro.org> From: Douglas Gilbert Message-ID: <8fbb619a-37b3-4890-37e0-b586bdee49d6@interlog.com> Date: Mon, 1 Nov 2021 21:56:00 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-11-01 4:20 p.m., Bart Van Assche wrote: > On 11/1/21 1:13 PM, Tadeusz Struk wrote: >> On 11/1/21 13:06, Bart Van Assche wrote: >>> This patch is a duplicate and has been posted before. >>> >>> Please take a look at >>> https://lore.kernel.org/linux-scsi/20210904064534.1919476-1-qiulaibin@huawei.com/. >>> >>>  From the replies to that email: >>> "> Thinking further about this: is there any code left that depends on >>>  > scsi_setup_scsi_cmnd() setting cmd->cmd_len? Can the cmd->cmd_len >>>  > assignment be removed from scsi_setup_scsi_cmnd()? >>> >>> cmd_len should never be 0 now, so I think we can remove it." >> >> Thanks for quick response, but I'm not sure if statement >> "cmd_len should never be 0 now" is correct, because the cmd_len is >> in fact equal to 0 here and this BUG can be triggered on mainline, 5.14, >> and 5.10 stable kernels. > > (+Doug Gilbert) > > One of the functions in the call stack in the first message of this email > thread is sg_io(). I am not aware of any documentation that specifies whether > it is valid to set cmd_len in the sg_io header to zero. My opinion is that > the SG_IO implementation should either reject cmd_len == 0 or set cmd_len > to a valid value if it is zero. For the sg driver in production, the v3 interface users (including ioctl(, SG_IO,) ) have this check: if ((!hp->cmdp) || (hp->cmd_len < 6) || (hp->cmd_len > sizeof (cmnd))) { sg_remove_request(sfp, srp); return -EMSGSIZE; } For the v1 and v2 interface users there was no cmd_len. It was deduced via COMMAND_SIZE(opcode) or by calling ioctl(SG_NEXT_CMD_LEN) prior to the write() to issue the SCSI command. Looking at the block layer/ SCSI mid level implementation of ioctl(SG_IO) I can see no lower bound check on cmd_len (which is 'unsigned char' so at least it can't go negative). Doug Gilbert