Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1306767pxt; Sat, 7 Aug 2021 06:52:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRERx8eha9JITPQuG4AHjZWF3uXqzcd+CT+VH2cQuZ2HOaXMMseCqMz8cS3CB3GarOThAg X-Received: by 2002:a17:907:3d93:: with SMTP id he19mr490677ejc.179.1628344346457; Sat, 07 Aug 2021 06:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628344346; cv=none; d=google.com; s=arc-20160816; b=LRquNDJ8vKmFWdOOqt/NAsDv+SsGkJ1fjQ32Lp78s8W7kmIJ+OjEeO39zELr1Nutb7 x1GvFN3TctUz8UuZ7GtU+9m1c8EDnrfvjls2a4nRir+Wn1lGXMur3N7YWQpz8peKCyYJ ij1h/2Tr89wM0TvsRZs9Vr4/XfqxH2dXbLezdcSQGt22GMB+467eWf5pCwSBAkj8TPU7 lcYmi2q/ZdrkupAh7jwNkIOmQ9bHuGQy+TZqCyQG6xL1Fe00cOUlx16C+vmRcdZ2XBzW xzl3HwIn1nTBdxTjtFsHT98Orqu5dInOLFzeUdz7+0DcNCj2EhfNF/eoBfZj26SGnhif pe8Q== 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=ZMFTuQL4XCv0rc6vS643hPfckJse4ED4dcB9MFxryLI=; b=p5o9tafBtD3M2NfuYyoh9BOEQmwg522lPvHcJlFqU1JMSaAwB3BhCY0H+CNr1aiFgA dAKrMqafEbj7jz9e2pL3AtSC703+9uXcN0yZrgPExIKJGhG4qzUPyEKnfPD89XaQatOf Kh3M6qzwf4VVAJf+KsmfVKncV5g/njBaQIvngSOwzAM/odNlZI3abKv6vIHUEBwUn6G3 aimlDmUe/WL1HpbVINaYBCLFGgWJemoBZzQwCS6w4DFF538LNIjAKAxL6eDKME0XlPZ9 1Iv7CG1nztOiau8I/cJ0CC97NlfOtpTBjXd2CKBbL8P1XtbIDyFjYpponAZRc++QjnFJ YczQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HSSjpVcO; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dh13si10964206edb.447.2021.08.07.06.52.03; Sat, 07 Aug 2021 06:52:26 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HSSjpVcO; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232324AbhHGNro (ORCPT + 99 others); Sat, 7 Aug 2021 09:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232210AbhHGNrm (ORCPT ); Sat, 7 Aug 2021 09:47:42 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 766BAC0613CF; Sat, 7 Aug 2021 06:47:24 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id a8so20890285pjk.4; Sat, 07 Aug 2021 06:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZMFTuQL4XCv0rc6vS643hPfckJse4ED4dcB9MFxryLI=; b=HSSjpVcOrBSkXxvrGMNszf1jTujgdJsnJypdiKYbb45gl3/tFrtk0oL+9RUiC3RZ8q m4StoJLry5Q043GaW7MMiZCfujNN6jwoFLLN3NT/yykYh0kM7kNsNb/85NBpy++xpfQ6 62k3kL1029qP8Ftx4tWDe12kMEwBdnJN/zJSHfWTvt39MZ3DrFdLIeLh+OuvnKHmh/Gz b9OE+rsTmPNk/icz/UKMWm1/cB0bnx7OaGVyjOnZ1emLdLRbJ5MntCctBIizFYkgNs29 AtIGl6kFgYACRh3+/j1kQaqgUWItnWLOviMz1eEHWOMLHuT2OQcSJPwoCqMfeE/l+gr4 w82A== 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:mime-version :content-transfer-encoding; bh=ZMFTuQL4XCv0rc6vS643hPfckJse4ED4dcB9MFxryLI=; b=GTe78ELVdXrlPF//QJJW72mg8zQhXaYqnwDU6LB+hWedcML6MxPHhyb9wX1buZEDk7 3GeKO5YARmtyrkZV+3a34O6H53hDGGrIWoJYalBUF6LC62VHmCcAd7TJANF1C3lva1VB ZmLf0qUM+ymvR8yJ55NZBSJgelPCQBDH7ZNL3Hsjwmj4qVXSmAs849qtC/OwEzArjPkL gJ1lVWfgEyMeynU2k5S4IdinJwgd8euGVoaXWsunzkomnQmIiyZXdgqPP30B4uIw4J9q GCGL5xXPz4LL2BIqN1Sq7w5dQqqv4OZUrcwzPVCE0BFFXnLCsZL8YUHVdsfAQgo2pNK6 fBVw== X-Gm-Message-State: AOAM533tNbVsxWdy42kAM/EiOeveXMwushiflZyNij0WwYiNtucfQm2n O+1AQW/Zo6fZFocwgs/mWYI= X-Received: by 2002:a62:e50c:0:b029:2f9:b9b1:d44f with SMTP id n12-20020a62e50c0000b02902f9b9b1d44fmr15981967pff.42.1628344043999; Sat, 07 Aug 2021 06:47:23 -0700 (PDT) Received: from localhost.localdomain ([45.135.186.87]) by smtp.gmail.com with ESMTPSA id bj6sm15849521pjb.53.2021.08.07.06.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 06:47:23 -0700 (PDT) From: Tuo Li To: martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, Tuo Li , TOTE Robot Subject: [PATCH] scsi: target: pscsi: Fix possible null-pointer dereference in pscsi_complete_cmd() Date: Sat, 7 Aug 2021 06:46:51 -0700 Message-Id: <20210807134651.245436-1-islituo@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The return value of transport_kmap_data_sg() is assigned to the variable buf: buf = transport_kmap_data_sg(cmd); And then it is checked: if (!buf) { This indicates that buf can be NULL. However, it is dereferenced in the following statements: if (!(buf[3] & 0x80)) buf[3] |= 0x80; if (!(buf[2] & 0x80)) buf[2] |= 0x80; To fix these possible null-pointer dereferences, dereference buf only when it is not NULL. Reported-by: TOTE Robot Signed-off-by: Tuo Li --- drivers/target/target_core_pscsi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 2629d2ef3970..560815729182 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -620,14 +620,14 @@ static void pscsi_complete_cmd(struct se_cmd *cmd, u8 scsi_status, buf = transport_kmap_data_sg(cmd); if (!buf) { ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */ - } - - if (cdb[0] == MODE_SENSE_10) { - if (!(buf[3] & 0x80)) - buf[3] |= 0x80; } else { - if (!(buf[2] & 0x80)) - buf[2] |= 0x80; + if (cdb[0] == MODE_SENSE_10) { + if (!(buf[3] & 0x80)) + buf[3] |= 0x80; + } else { + if (!(buf[2] & 0x80)) + buf[2] |= 0x80; + } } transport_kunmap_data_sg(cmd); -- 2.25.1