Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2568335pxt; Mon, 9 Aug 2021 03:51:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyurwYjR5Pn3UaFb0q0Fu0vzsTz9i81RuaO2ix2xcWMcfxFxS2xUkbZ7csZtXj7/BmfQg26 X-Received: by 2002:a05:6402:202:: with SMTP id t2mr11829698edv.116.1628506287042; Mon, 09 Aug 2021 03:51:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628506287; cv=none; d=google.com; s=arc-20160816; b=bN3XPS+KcTwJGPnX4hi4LKjISoOTENw9nFLyUuhTI++X3CHX+vrOiRGlGYyBiYtA6p nTzUcGRRskVfAqZx9KBRl2bpyfYiAYuvIvqe1Tq/sa0rRM4ItaGLM5kAK03TgYbM/+HO /sVF77q8fJw6yh5MliYhq/u3S/wlxvE2XGbD1lvnq1OUGq3IWKA7FtU7+wb4w5KZ417J VoDFYDNbWaJCu6jUz+TDl555Y82nVB3DeaU4npkTunzPz4uTA2eMfrHTsrE2lA9qEm04 eUI3gr/l3LUa0FWeKLAlacjo87OWZoKR5Q5aBtlpfb5LGZ4MH2YmUhhzyPRI2BEmrC87 oF/g== 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:dkim-signature; bh=oyK3DK7dZ8B3CuDhQ4Icy2bryrgMxTkDyrctLoPcTvA=; b=fS/wAOVexpvrn1+pANzwYh1IqmrsG6LjzQo+EAljSbWBZy6gyUK32HMxu+jGZuYxzV hdIAjDXiuKB41YV3G/9c0ICMRls2J2b4Rge5ten1M4v14MJ81eTANCYVJFU2sZbc0Z29 0LraKwS5mI1+OyxqA6xIRFjHwoMQbYNhE02UZgzmOKfyaz1+vf9ATsDoPZcey6wjPAtO v5JlCUqFFrsFoydOhIwg0O3XwL5DJ1IGDBbn+qasVhnYPYUl+SYTNBbRADxRY2gk6wJ/ odw6Rov54FOVxUixjkFWmyWkPlNZcSsIT5MxYElfptIerSvitCC8O5WEBMHMV3PPCBWi fBUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="EB4/zfNB"; 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 x23si16192195ejv.167.2021.08.09.03.51.04; Mon, 09 Aug 2021 03:51:27 -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="EB4/zfNB"; 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 S233657AbhHIKgc (ORCPT + 99 others); Mon, 9 Aug 2021 06:36:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233658AbhHIKg0 (ORCPT ); Mon, 9 Aug 2021 06:36:26 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 195D6C0613D3; Mon, 9 Aug 2021 03:36:06 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id h24-20020a1ccc180000b029022e0571d1a0so11178959wmb.5; Mon, 09 Aug 2021 03:36:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=oyK3DK7dZ8B3CuDhQ4Icy2bryrgMxTkDyrctLoPcTvA=; b=EB4/zfNBdczLKQVrCD4PktpowRlF8xRDE8RcYyKzzQnA2mC8kXnhDQfxOc29y4YxuK UEocQe3EyD6UHrZCEN3QwHJUwc+fwMT4J2H2miBaBvL/piyP1EVz8c2SwBS8euyMOQkP Z86pKEo9K8dVnuG0nIhk/ksmyGHYjLh2l5IlOcSl64lSzjwItYaICIALu9Aya8czliPm LTAtTVbHYlj7jgrkANDQCxU3D8KBovswX1UxXnQRyj+snv7KqOSz6CKSIYIXVsmK7CAp aYZUb86p4fFX4R2/JkH26mvAm/1n3GB5ahR68qRoJiNWaHrCdnRBPg1DlpX0Y683RKxw 284Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=oyK3DK7dZ8B3CuDhQ4Icy2bryrgMxTkDyrctLoPcTvA=; b=J4IYSy3vBAMY6ZsPIDvcSBUa9t4UAQVt2NvrYxJLaRQQu78Kpjblwmn9eUNNHPxBAL kM7UXBpBSkCASxMk7PnipjP7sF4z3Z4ogCHLINX7bgYe2qOzVWev4Fyif9dl7ymZrdHa nkq71Gck3hafO4BBiHXbuqhrLHdJmABchBK/c80HPhEJS/Odp8xyYRKfdMdNCQQybTcq ITKSuhUtOhNhfz2LDiQM+ppWiYQswxjdTBx5j3A9LicjeuXiyJ8qR4acoK7oXSg+ycqN mLgrrLcczvAPQ646u3zKMdeolNoLIdh/oTiMFJCJY6hRaKVzBabhL2pfbsZ8BWXqfYIt 17TQ== X-Gm-Message-State: AOAM532meznFKKJrXd6ihJpBEPGagXjNhcep6RBQhE0KRJfnG853vLmy y22433kK4jHJsBS3o4yPF0q1KT5eJ4Q= X-Received: by 2002:a1c:1b4b:: with SMTP id b72mr1654692wmb.168.1628505364701; Mon, 09 Aug 2021 03:36:04 -0700 (PDT) Received: from [192.168.178.40] ([188.193.135.183]) by smtp.gmail.com with ESMTPSA id i14sm14504278wmq.40.2021.08.09.03.36.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Aug 2021 03:36:04 -0700 (PDT) Subject: Re: [PATCH] scsi: target: pscsi: Fix possible null-pointer dereference in pscsi_complete_cmd() To: Tuo Li , martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, TOTE Robot References: <20210807134651.245436-1-islituo@gmail.com> From: Bodo Stroesser Message-ID: Date: Mon, 9 Aug 2021 12:36:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210807134651.245436-1-islituo@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07.08.21 15:46, Tuo Li wrote: > 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); > I'm wondering whether we should better put the transport_kunmap_data_sg into the else-branch of the if (!buf)? AFAICS, calling it after transport_kmap_data_sg failed does not cause problems, but I feel it would be cleaner. Otherwise it looks good to me.