From patchwork Wed Apr 17 21:44:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10906257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EA7017E0 for ; Wed, 17 Apr 2019 21:45:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69D5428A93 for ; Wed, 17 Apr 2019 21:45:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E54028BA9; Wed, 17 Apr 2019 21:45:37 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 07E7F28A93 for ; Wed, 17 Apr 2019 21:45:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387963AbfDQVpe (ORCPT ); Wed, 17 Apr 2019 17:45:34 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35450 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387962AbfDQVpe (ORCPT ); Wed, 17 Apr 2019 17:45:34 -0400 Received: by mail-pf1-f194.google.com with SMTP id t21so88580pfh.2 for ; Wed, 17 Apr 2019 14:45:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ATXzuJAeM11DHVbKy+mLtJ4hzU63/8FkCHfSVCsvUbI=; b=HWlZmGWxEEjem/FsGNr5iKDaWsOxYdkHQptTmFWPeWt4IlNvIcYcKXzxI3espFRNB9 0lkscTCxusYJ92MgIAMEXbVJAFSeqIrMWQD2x3h9itp9fZhaM1PGM632uMNt6XPO8xRK ri39QKE5mnIqgNfzPHU7cfu740+vZHtmSkzodHv1VCvo6Lf0CS3CkSTrXmv2uU8c2lgv kYbs0D/SwG+qfWaKfc1rsAaoMEe0qYfuqImtBiuqn5nswwr0en7v8pNKI3wt5H/YI+wu +Hj3aOuxNthLGzszAHKNstdflGI1k+FtM1wBsZ+r4vUZXSVj7NrTPBDlSnU+2lTEz3K0 DOrQ== X-Gm-Message-State: APjAAAVSeZcJ2p4IQEufgZIP4C/hyTDTtTr1zL4cMne8OJlAS7QuQoP7 Dao0jrg9P2B2XdvNZH4u+uIklQOs X-Google-Smtp-Source: APXvYqzonyRVZg4TBg21mxA/RXitNZNNMnAPPuRo10W4+EO9MHRv37FbKitYkOp71vAXo7k6cXBzrQ== X-Received: by 2002:a63:f707:: with SMTP id x7mr86153881pgh.343.1555537533392; Wed, 17 Apr 2019 14:45:33 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id d68sm219314pfg.16.2019.04.17.14.45.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 14:45:32 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Himanshu Madhani , Giridhar Malavali Subject: [PATCH 33/34] qla2xxx: Avoid that qlt_send_resp_ctio() corrupts memory Date: Wed, 17 Apr 2019 14:44:42 -0700 Message-Id: <20190417214443.243152-34-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190417214443.243152-1-bvanassche@acm.org> References: <20190417214443.243152-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The "(&ctio->u.status1.sense_data)[i]" where i >= 0 expressions in qlt_send_resp_ctio() are probably typos and should have been "(&ctio->u.status1.sense_data[4 * i])" instead. Instead of only fixing these typos, modify the code for storing sense data such that it becomes easy to read. This patch fixes a Coverity complaint about accessing an array outside its bounds. Cc: Himanshu Madhani Cc: Giridhar Malavali Fixes: be25152c0d9e ("qla2xxx: Improve T10-DIF/PI handling in driver.") # v4.11. Signed-off-by: Bart Van Assche --- drivers/scsi/qla2xxx/qla_target.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c index 302bc43cc061..ed02ac51183d 100644 --- a/drivers/scsi/qla2xxx/qla_target.c +++ b/drivers/scsi/qla2xxx/qla_target.c @@ -2329,14 +2329,14 @@ void qlt_send_resp_ctio(struct qla_qpair *qpair, struct qla_tgt_cmd *cmd, ctio->u.status1.scsi_status |= cpu_to_le16(SS_RESIDUAL_UNDER); - /* Response code and sense key */ - put_unaligned_le32(((0x70 << 24) | (sense_key << 8)), - (&ctio->u.status1.sense_data)[0]); + /* Fixed format sense data. */ + ctio->u.status1.sense_data[0] = 0x70; + ctio->u.status1.sense_data[2] = sense_key; /* Additional sense length */ - put_unaligned_le32(0x0a, (&ctio->u.status1.sense_data)[1]); + ctio->u.status1.sense_data[7] = 0xa; /* ASC and ASCQ */ - put_unaligned_le32(((asc << 24) | (ascq << 16)), - (&ctio->u.status1.sense_data)[3]); + ctio->u.status1.sense_data[12] = asc; + ctio->u.status1.sense_data[13] = ascq; /* Memory Barrier */ wmb();