Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3362770pxt; Tue, 10 Aug 2021 01:38:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1DEicAuAZj8++jIXg1s8ydiWIBwIcVhljpBjp2ZGS91ruTw3pkiIviQvoqNYZtYI6G1AZ X-Received: by 2002:a5d:8744:: with SMTP id k4mr249460iol.9.1628584720579; Tue, 10 Aug 2021 01:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628584720; cv=none; d=google.com; s=arc-20160816; b=W7MkMuU95siuxa7gwCn99SUFj9ZF4GrK9HVNXl2f16si1gEWLeHyRm5aYrQnMDzwT/ Q0Zk5owCNEHbII23ADAOm9uu2bdfY7yAjgt6dtXH2/TUqgcfHxKOAr8oJ6x7uFGdXDvx rnZWPWzQ9JK8FLiXQWq61V+XZZmGNi+8P3740sjnkJCoihUHN2eo4xmJEG1ZucdfTK5Z EXkwfp654d/9Ixh9TARulwL/Tt+JVufmybMOXDNlpu3Q5r2dPeYk9ELV+oqIL3bb5z/h pxn+4pZtZZQ2Ygn2ejcdSj8f3buqWQunu9M1oBNKzl8Tle0xPqw0td6dCuk91BqsOBrm d9Yg== 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=gWww76GCF5bdJ3wwOyrVrOe81eD6ccbw3CbNhzGl6sA=; b=tBg2V/4cUGE3CqJSZ4N3CfWsiRfVYhnOBhuhbYyZueeUcILrOmiO6lU+pd65VYAT92 WhBlRwk6lOVupylF8uddO2lNsoFhWGOtLZtKLneLFJ7BA2CuYEM5s5rxoBHvG2nrlPzD GJqNFb6hKBd1STTVmEg3U2AH0C9tN3ORRaX8dp5PvWv9wZN2/AhH8yS49CGuTEEpzpSU GLEDeKUluZTMGZrQvsCM793JikgWe+FZ7lrPpGQL7EtC9VRBIXxQptH5AZOhdMDjCwTB juQgsUf7urLvNveOE2iEAu8M1tM7KywZKvjsCHWIb24bi28D4+VQ/JcfNj9NzjS4sJhw mDdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NZkGabqA; 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 m6si21164929iol.83.2021.08.10.01.38.28; Tue, 10 Aug 2021 01:38:40 -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=NZkGabqA; 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 S231569AbhHJHTH (ORCPT + 99 others); Tue, 10 Aug 2021 03:19:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbhHJHTG (ORCPT ); Tue, 10 Aug 2021 03:19:06 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23BD9C0613D3; Tue, 10 Aug 2021 00:18:44 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id r6so2626157wrt.4; Tue, 10 Aug 2021 00:18:44 -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=gWww76GCF5bdJ3wwOyrVrOe81eD6ccbw3CbNhzGl6sA=; b=NZkGabqAvmYmZUO16jJsqhjL/CVU0Sj7skB8PuJhN/s7osQ3QymAZOFTma81Cnb1gT gyTR2VraTsCp515ookPa3CDbMKBwIZF6CDbBRp9+yA9YQm6QJ8VhaAzGEBv+tRZKt6J+ bMdoQyA0GtZ87GGhT2cO8yvSXHBpjWqax6Sdl4mGfTpyV0O8LSqbRK9FHeC9J24mCXsk uXti+uGGUSHGAAJPfwbtGGszxhLiNkkaHLBLXnYidNI+9GnrH/qH08ouH5pgtoWwxT02 +dCFV7bh6Cq6DDvneOO5EEhh6zzjUwc2/wWY3isQD2YQSL/HO/sBie9U48PTfn2w5+x7 cIig== 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=gWww76GCF5bdJ3wwOyrVrOe81eD6ccbw3CbNhzGl6sA=; b=eweDzgqKh4sUcNpEuLEJZ47OM4weXu0FeIwDkMQTo4HEe7DDM+iyt4Q0u0xOsU3niJ RmY3zG4vD0hmcu4DvLEsY0gd8x1bcq8jzt9UobtopVdezTEi/HXJnyOofCAmYnSxS+6b aD2fasKahjubd+6Wry6nbvFUq8d2Gldu2uv1+VOdGOTa5Ir42eqtRLmiLn2NN0/Q6pKw 6qAVVEYEWlqmbOGb1EQvOUEjapH1cPUhfDhZmI7AKnuSJnwaDsFPaOYwuT1zXj/XoIqo J+rIg1rx3E3XF8ChYdAZHTf4ycT3QzbVAxFhs3FJ/ZgIoha8poOPKg4VDui4IVPcNzK5 mRPg== X-Gm-Message-State: AOAM532bKvVYDJG/6yikB5GhKIMUvA8+yliMs2tBwOZfQGqURTsCfJMv GhEIibpfUZBWosgQsNspu/k= X-Received: by 2002:a05:6000:18c2:: with SMTP id w2mr29071731wrq.282.1628579922602; Tue, 10 Aug 2021 00:18:42 -0700 (PDT) Received: from [192.168.178.40] (ipbcc187b7.dynamic.kabel-deutschland.de. [188.193.135.183]) by smtp.gmail.com with ESMTPSA id d8sm22313152wrv.20.2021.08.10.00.18.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Aug 2021 00:18:42 -0700 (PDT) Subject: Re: [PATCH v2] 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: <20210810040414.248167-1-islituo@gmail.com> From: Bodo Stroesser Message-ID: Date: Tue, 10 Aug 2021 09:18:41 +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: <20210810040414.248167-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 10.08.21 06:04, 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 and call > transport_kunmap_data_sg() only when buf is not NULL. > > Reported-by: TOTE Robot > Signed-off-by: Tuo Li > --- > v2: > * Put transport_kunmap_data_sg() into the else-branch of the if (!bug). > Thank Bodo Stroesser for helpful advice. > --- > drivers/target/target_core_pscsi.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c > index 2629d2ef3970..75ef52f008ff 100644 > --- a/drivers/target/target_core_pscsi.c > +++ b/drivers/target/target_core_pscsi.c > @@ -620,17 +620,17 @@ 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); > + transport_kunmap_data_sg(cmd); > + } > } > } > after_mode_sense: > Reviewed-by: Bodo Stroesser Regards, Bodo