Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3426339pxk; Mon, 28 Sep 2020 18:03:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiujw97AWv/Lvf9U9b6aFLIs7+R9gBPHxkObj9E1pUmjJ+mmLMUl65bU3uidl+H0LgCbAC X-Received: by 2002:a17:906:194b:: with SMTP id b11mr1367938eje.159.1601341387586; Mon, 28 Sep 2020 18:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601341387; cv=none; d=google.com; s=arc-20160816; b=bXCD7QYCY26BlteEyjtxLaiE+xwvSL+fDREwqIq8C3YBNR/9FL9h+3Gw939rL/an7q m1ZwM/M5dmGx5rTLvpS5TzYAfbYxaoOr2enXR4vV0fTwMYlvhGjS+FWlLP6tJCK35HBN ggz8c/rWGVfOFJ2dVBGTyUfIF9FGVyMkKzKjFOtE3oHb3LY49esRVz+yN4kiWAaCm426 CeuCDYP00OtZMJTylz73nxrUFKGFgIF9840/EFQTpRD65wNCuztqccJCRo422ZZcSWq8 yd2eh1dlfxDbfQ5ppBSymva+GFGRsmR9LDvswyWHuAjakntWHmLnU8NiLL/zXQ34tI/w VLXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=urjSXJ4Z8tUOTm/hAyyED2ePbjQxEB36PzIbjHccclM=; b=fcRUNz4ttIECsUsuLhuhDrQrr+1JvWrRyaAH7EWFSVFCwDYkWnHkdlb01/LAJIE3SM cvzyHcQv1JIhlEPa8/iBorYnD2gwncZ+GFHZySXllmEENFx1s0XAyRjoxmBw684+vawE 7x5fLuWxgkrSGIDrShfQkzdDFipLU7I7OjRbAzkQo/4hx/CFjax0fJZREK9Uv0awoahu pcAuyjeaBKPqulrsN/ySOSSowivy4ZxTtq49ErnGZFWhAlOamr/FQ/06JrF0iSqon1ov 2zk3TJCEP5l3pXYOzGzmjzrMWka30sdhcyG2HdT8LLm3GR4pf7Cj8RXbqBURrmBUJ78F BztA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u18si1808260edy.380.2020.09.28.18.02.35; Mon, 28 Sep 2020 18:03:07 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbgI2BBT (ORCPT + 99 others); Mon, 28 Sep 2020 21:01:19 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60268 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726698AbgI2BBT (ORCPT ); Mon, 28 Sep 2020 21:01:19 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 77560ED12442A06B7F78; Tue, 29 Sep 2020 09:01:17 +0800 (CST) Received: from [10.174.178.248] (10.174.178.248) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.487.0; Tue, 29 Sep 2020 09:01:15 +0800 Subject: Re: [PATCH] staging: most: don't access hdm_ch before checking it valid To: Dan Carpenter References: <20200928104838.189639-1-jingxiangfeng@huawei.com> <20200928114857.GR4282@kadam> CC: , , , , , , From: Jing Xiangfeng Message-ID: <5F72875A.8020900@huawei.com> Date: Tue, 29 Sep 2020 09:01:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <20200928114857.GR4282@kadam> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.248] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/9/28 19:48, Dan Carpenter wrote: > On Mon, Sep 28, 2020 at 06:48:38PM +0800, Jing Xiangfeng wrote: >> In try_start_dim_transfer(), pointer hdm_ch is accessed before checking. >> This may lead to a potential null pointer dereference. Fix this by >> dereferencing hdm_ch after calling BUG_ON(). >> >> Signed-off-by: Jing Xiangfeng >> --- >> drivers/staging/most/dim2/dim2.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c >> index 509c8012d20b..ccd7cc7545e4 100644 >> --- a/drivers/staging/most/dim2/dim2.c >> +++ b/drivers/staging/most/dim2/dim2.c >> @@ -148,7 +148,7 @@ void dimcb_on_error(u8 error_id, const char *error_message) >> static int try_start_dim_transfer(struct hdm_channel *hdm_ch) >> { >> u16 buf_size; >> - struct list_head *head = &hdm_ch->pending_list; > This is not a dereference, it's just pointer math. In other words: > > struct list_head *head = hdm_ch + offsetof(struct hdm_channel, pending_list); Thanks for correcting! > > So the commit message is wrong because this cannot lead to a NULL > dereference. It's better to just delete the BUG_ON(). We don't really > like BUG_ON(). Checkpatch will complain about them. An Oops gives > basically the same information as a BUG_ON() without completely killing > the kernel so just dereferencing a NULL is preferable. Finally, we can > see from the callers that "hdm_ch" is never NULL. > > regards, > dan carpenter > > . >