Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8738140rwr; Thu, 11 May 2023 05:44:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7u0l6ZfAFiIJahSX7vSIG8wPbeLze8l6tL8UbK4TnNGxlGW/Vmc0SRiGqcV2cQAz2OGahm X-Received: by 2002:a05:6a21:788d:b0:ef:8de0:6a5 with SMTP id bf13-20020a056a21788d00b000ef8de006a5mr18190528pzc.3.1683809061081; Thu, 11 May 2023 05:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683809061; cv=none; d=google.com; s=arc-20160816; b=LpjLSqNedHh0pyaLeSAHePmTHy75sivgJzLHYRTchHeb61QfSWgWKsfgVebebAPeVL K7zdCwFJEOD4mVXrW6O2XQ3ogshCSsu8zDU1zyQEBB93LIGvJUZu/bZ+KOnbM5TGUEdI VpP/f8x0Eya3wJXcM4TbLEnJJ4o8ZEPKNQGhP7ltVRZxp6EN5OIjScSkPXJw2KnQBDXy Q6lh9ka0bmQmKwZkfFOQx2P7xev/zY+inC96ToxqGc1+/9eS6+N5LULRtGYO7x2DVBj9 VfEY1rHqYaIc/M3a27BbVf/i0IK64q3zHrASETQ49fjcUWGnf/+VeWRmBurMZmA5bJ3V Ysjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=83yvFZ5iIQbRFdlm2LdYEQOdrJZ+zypJQp4T17WtAcY=; b=dbdN5hfAV36RLFQ07Pj1B6wLGGRIh8SBLUunEnOJHLbolLvZIes4qHbD+/k1V4pLad nUXZ8ijwSWLUWCg5vSRGQo0Wh1ybAwRbKk8Mf2yzBe3P4xZHaUQx2q7/rgv72MzA7K+C DPIG5ndatxQugsgkonhRYf4M6PshXkdtjiXTjRsEqieZNY1R0HjGbM7f4LF21Q/EsdMg Cbv/2PmcScg2/QftPVyF5Ona89p0mv1XH9B11dgU7z9Y2x90QKrSSieQhXV82VuCaYM6 0QEW0CYmPXSXv2Wq9ZXbZHeU8cXzEvhKwdPgTq2ArPrDNMdUs+e1540sO7MV3Fm3Jvuy WVBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=cq5t3ADL; 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 r27-20020aa7989b000000b00643b6fa7d34si7547858pfl.214.2023.05.11.05.44.06; Thu, 11 May 2023 05:44:21 -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=cq5t3ADL; 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 S237750AbjEKMep (ORCPT + 99 others); Thu, 11 May 2023 08:34:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237570AbjEKMeo (ORCPT ); Thu, 11 May 2023 08:34:44 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6146A10F; Thu, 11 May 2023 05:34:42 -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 9EBF71FE91; Thu, 11 May 2023 12:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1683808481; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=83yvFZ5iIQbRFdlm2LdYEQOdrJZ+zypJQp4T17WtAcY=; b=cq5t3ADLmbRHetVLwL+ZtnNYPgqEVGy7WrBJZsI0DwR/doyLu8x4MjNibaN+2guhfHSLtX PoB6jMdFGJg+LnXetFib1emaEo+/TVfA6Na6NS6H06565ExRwhzXYf2liUkt3CD+3fJw9H iXFgSf8y/QLmAVADghGsj5z7xJi9aZk= 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 DC41F138FA; Thu, 11 May 2023 12:34:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7e1eNODgXGQjCAAAMHmgww (envelope-from ); Thu, 11 May 2023 12:34:40 +0000 From: Juergen Gross To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Juergen Gross , "James E.J. Bottomley" , "Martin K. Petersen" , stable@vger.kernel.org Subject: [PATCH] scsi: Let scsi_execute_cmd() mark args->sshdr as invalid Date: Thu, 11 May 2023 14:34:32 +0200 Message-Id: <20230511123432.5793-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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. This can result in false positives when looking for specific error conditions. In order to fix that let scsi_execute_cmd() zero sshdr->response_code, resulting in scsi_sense_valid() returning false. 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. --- drivers/scsi/scsi_lib.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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, struct scsi_cmnd *scmd; int ret; - if (!args) + if (!args) { args = &default_args; - else if (WARN_ON_ONCE(args->sense && - args->sense_len != SCSI_SENSE_BUFFERSIZE)) - return -EINVAL; + } else { + /* Mark sense data to be invalid. */ + if (args->sshdr) + args->sshdr->response_code = 0; + + if (WARN_ON_ONCE(args->sense && + args->sense_len != SCSI_SENSE_BUFFERSIZE)) + return -EINVAL; + } req = scsi_alloc_request(sdev->request_queue, opf, args->req_flags); if (IS_ERR(req)) -- 2.35.3