Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8799446rwr; Thu, 11 May 2023 06:27:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7suUipfVBvPXaoJYhmYXnNlZ6QUDkQYOrYAAEX9+ptC1JZiRz1p6rXmEKebcnUNFS2WqKI X-Received: by 2002:a17:903:806:b0:1a0:549d:399e with SMTP id kr6-20020a170903080600b001a0549d399emr19530424plb.21.1683811670692; Thu, 11 May 2023 06:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683811670; cv=none; d=google.com; s=arc-20160816; b=yYXTMPNZZ6z0KbbKnYWJ2lOdV6FonjjA/7ZrLNPEC0t0SzJhqMpWhQHWJ/hLTudxmz mLQkIKoXGRH7EHBJBu7QO9zVKti0T8nBv5q7qwZA1dD5bHL9+F35WaEMk5CvyaBFzRGc Y6AOaFdFLj7lRSnbQvepT/ZjGmX6j1TtvkGkXtr7IiG2HSadjzgQeo7n3Cp6poGZoUpW MGtv7c+apO7wF8xML2/7/Zo9rsK46pAqf419TfdOEID6bgLkAA/zTQMy4YJTzZ2Q4jj/ QDeLrANAU3WtRzUatipL53TTkOpH/5ilJrt9ZyrDjfal02pU+n7QF4yyLWl4aDfm8lxE 6jFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=2kHWk0gaCy7sFq5ZjcvtYIgAcrVlu1oZLofczV71BSo=; b=kskhGHKZfzrR9PfToSz6qhnGjtkKnrJQW03QX13qWbNOrOjf+LVAiJazbWdGcEnMut YEXREXdz4GySI36z4Jj+8rYgnvaBpC4OQvGNfis8m4uNdjJaJA3r4XlzRakTaWG4XDpa 96cm3u9HaOh7ZyVEiykuY8mJquHR3Es249ScMsY+fS1EPhGwLxv+fJTl2qE43Nf/Qdwm yovtiu4Zx0NsZMr8J5wDEmvGjulZSscIKUt5l9zvbATv0Suc/btcrDjIjPbWwuNG9/U2 VfM/SQe8tnlVj37zlcdKN8pf+FRLhUfObf2c01MpLUhtYyrD3AtCl4NX5RSJxNjJZ0w6 AEtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=GCERDsj+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020a170902694300b0019ca7a76d68si6451098plt.67.2023.05.11.06.27.36; Thu, 11 May 2023 06:27:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=GCERDsj+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238056AbjEKNLZ (ORCPT + 99 others); Thu, 11 May 2023 09:11:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237796AbjEKNKw (ORCPT ); Thu, 11 May 2023 09:10:52 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A52205FEB; Thu, 11 May 2023 06:10:49 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5096C1FDF7; Thu, 11 May 2023 13:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1683810648; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2kHWk0gaCy7sFq5ZjcvtYIgAcrVlu1oZLofczV71BSo=; b=GCERDsj+FKy6LW7J6+MdfkxxC8Acz6TXWjoh8a8oHTEWiH807oBwtkJzaaIqIGzyvLDzN+ bbV4arMw5cn+/Z/Fy/ko5a3z/QBEwJx+w61/t8uJSQObCV9XplDbgQE65tSZrzs9Xx7IIm mfmAJ8cQSET96RDEtf6ud/bW4O0Vv4M= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 13816138FA; Thu, 11 May 2023 13:10:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id exAqA1jpXGTWHAAAMHmgww (envelope-from ); Thu, 11 May 2023 13:10:48 +0000 Message-ID: <095a2264120ad51d0500c4ce8221be2f88a9537e.camel@suse.com> Subject: Re: [PATCH] scsi: Let scsi_execute_cmd() mark args->sshdr as invalid From: Martin Wilck To: Juergen Gross , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Cc: "James E.J. Bottomley" , "Martin K. Petersen" , stable@vger.kernel.org Date: Thu, 11 May 2023 15:10:47 +0200 In-Reply-To: <20230511123432.5793-1-jgross@suse.com> References: <20230511123432.5793-1-jgross@suse.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2023-05-11 at 14:34 +0200, Juergen Gross wrote: > Some callers of scsi_execute_cmd() (like e.g. sd_spinup_disk()) are > passing an uninitialized struct sshdr and don't look at the return > value of scsi_execute_cmd() before looking at the contents of that > struct. >=20 > This can result in false positives when looking for specific error > conditions. >=20 > In order to fix that let scsi_execute_cmd() zero sshdr- > >response_code, > resulting in scsi_sense_valid() returning false. >=20 > Cc: stable@vger.kernel.org > Fixes: 3949e2f04262 ("scsi: simplify scsi_execute_req_flags") > Signed-off-by: Juergen Gross > --- > I'm not aware of any real error having happened due to this problem, > but I thought it should be fixed anyway. > I _think_ 3949e2f04262 was introducing the problem, but I'm not 100% > sure it is really the commit to be blamed. > --- > =A0drivers/scsi/scsi_lib.c | 14 ++++++++++---- > =A01 file changed, 10 insertions(+), 4 deletions(-) One nitpick below, otherwise it looks good to me. >=20 > diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c > index b7c569a42aa4..923336620bff 100644 > --- a/drivers/scsi/scsi_lib.c > +++ b/drivers/scsi/scsi_lib.c > @@ -209,11 +209,17 @@ int scsi_execute_cmd(struct scsi_device *sdev, > const unsigned char *cmd, > =A0=A0=A0=A0=A0=A0=A0=A0struct scsi_cmnd *scmd; > =A0=A0=A0=A0=A0=A0=A0=A0int ret; > =A0 > -=A0=A0=A0=A0=A0=A0=A0if (!args) > +=A0=A0=A0=A0=A0=A0=A0if (!args) { > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0args =3D &default_args; > -=A0=A0=A0=A0=A0=A0=A0else if (WARN_ON_ONCE(args->sense && > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 args->sense_len !=3D > SCSI_SENSE_BUFFERSIZE)) > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0return -EINVAL; > +=A0=A0=A0=A0=A0=A0=A0} else { > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0/* Mark sense data to be in= valid. */ > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0if (args->sshdr) > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0arg= s->sshdr->response_code =3D 0; We know for certain that sizeof(*sshdr) is 8 bytes, and will most probably remain so. Thus=A0 memset(sshdr, 0, sizeof(*sshdr)) would result in more efficient code. Martin