Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1956582rdh; Tue, 26 Sep 2023 08:15:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2K7rrSbvvopUHEfQmQde3fESiEN27Gm5RB+mFWSmxEJU0U3q8pQ62p+qiM+TG/XJXf0FO X-Received: by 2002:a17:902:efc1:b0:1c3:9aa7:66e1 with SMTP id ja1-20020a170902efc100b001c39aa766e1mr7200332plb.69.1695741313405; Tue, 26 Sep 2023 08:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695741313; cv=none; d=google.com; s=arc-20160816; b=mlnU+HdIIcQ4eifgnSDGvEnpFDSG7nswckwSuQLuBGQWUNC0y7lqsb0WgCYKmFWmEj K7m/xV1PKcZ/QV23Bxyes1IijZLCyFzmQlIn48I2oWbndZ18iIEz+nzoBYRmS6Ozb9DO 95aIRIY5RZcUztJHBIpdcFTEMUzivFNhRyOu+u3J/VggvDUQIdIZKgi4VHPmkApnm74f Z2AXs3onSRXEopsPpx3UV25L03s1219tFST33Nfa1fteszQUF4tKDr9uA4lIkgFROxAn 2XlFWhKV6HZ+U5c3JLXpYs6AIdCmukSH7fVP3mcAXTAZh6F0vA7FDsMoAk4PAWIrxSu4 9FMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=7xHsjPqk6JJBUwczwrhg2APBTdxlZcsovPFUPf8oBcY=; fh=5H+UFYr6QOwUPv1nIC+0uzmOicKpQVUFFmzNx1r4Vf4=; b=MXEAs9MgFwi40faDsCfgUNLFaAR0GBlcxzQ1B5MR3mT5E6rhA3QBicJPhjmpX03/DD lXQvpJbMHHk+bped5rVNH8S6qBRnayaDU2kfppMp/O9/pvkOgUSnv/0+m0oBxLuDhcni QmN24AgKtOfSDDXTd2fjsvP4FSV5IQTpv+O8XnDLQLuSzmM9/n4nGCSh+kuPtJ1u4zce LEY63mMQ8lKEnQMYFgUxt90Y5lFfYoydORN9l/QNCCqwdlOymWWWLCZgWkGUw7UmSXC2 i0z+maf+ba2JP4rdEC0IRNPlmI3EsCCXurBDSRU+Pt+IIdYxIvPFbkD9aCOAJx2STOQW /lmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M9ay2qpQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l11-20020a170903120b00b001c3845d008csi13176462plh.424.2023.09.26.08.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 08:15:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M9ay2qpQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id BC1F08073DC6; Tue, 26 Sep 2023 07:01:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234874AbjIZOBW (ORCPT + 99 others); Tue, 26 Sep 2023 10:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjIZOBV (ORCPT ); Tue, 26 Sep 2023 10:01:21 -0400 Received: from mail-yw1-x1142.google.com (mail-yw1-x1142.google.com [IPv6:2607:f8b0:4864:20::1142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6351AFC for ; Tue, 26 Sep 2023 07:01:14 -0700 (PDT) Received: by mail-yw1-x1142.google.com with SMTP id 00721157ae682-59bf1dde73fso112368017b3.3 for ; Tue, 26 Sep 2023 07:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695736873; x=1696341673; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7xHsjPqk6JJBUwczwrhg2APBTdxlZcsovPFUPf8oBcY=; b=M9ay2qpQ7AmTwO8+Ktsgpp80OBtSZ/XeqvqK0Wt8fC2KPLmlsX4YXiXNADyURIEHFs 53zSz2h2yR78iewy4NFMa4kd98GzzJyfBBan2PQ6OrZY9sMO1ehWcgBo+uOXNLlzru5A 6yYNil9qCZ+88Gie84WkgzHyMVHoBcMxO5hns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695736873; x=1696341673; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7xHsjPqk6JJBUwczwrhg2APBTdxlZcsovPFUPf8oBcY=; b=Zh18h7XW+/lRX1zRJ8Yb7y2S4JdcUfV4NMMs4UicGFR8mWCfQMX7bCPRmqIYlg4IY0 hTmU+R75szDeyybt0VSo6V/1gJItgcmG119aDFWiJK2OiZNlyKYCGlil48kYiYjzX73K tzGg1VFmop76pO0mZkct4HvVhYD+GodfprxO6sm+kc3crTtEWcceuyRHfvPtkFORoN4O x0q6IwGd2IRfthfxectYIfq7GGNVZctU4C8n/TnbC2C0dp/RxQtpmN1mZ0gdmxGXZRDo 0Do3CynU7wIQadOcx8EVKsKVmDZKR1C/2elMZJtMRRY2phGpNu+bCwCiBCnbc1pVv+l9 VW2w== X-Gm-Message-State: AOJu0Yxgg/zNQu0bXgMAvy4OySpfQ3WyF2+sEXhC2ht8Bx7el7Nc09Jg y2WTrFdvobWFT/D+4RQPF8LPqRnX3xLEQhamvCmumw== X-Received: by 2002:a81:4f4d:0:b0:586:a170:7dbe with SMTP id d74-20020a814f4d000000b00586a1707dbemr9693811ywb.13.1695736873520; Tue, 26 Sep 2023 07:01:13 -0700 (PDT) MIME-Version: 1.0 References: <20230921131201.157767-1-lma@semihalf.com> <20230922063410.23626-1-lma@semihalf.com> In-Reply-To: <20230922063410.23626-1-lma@semihalf.com> From: =?UTF-8?Q?Rados=C5=82aw_Biernacki?= Date: Tue, 26 Sep 2023 16:01:02 +0200 Message-ID: Subject: Re: [PATCH v3] drm/dp_mst: Fix NULL deref in get_mst_branch_device_by_guid_helper() To: Lukasz Majczak Cc: David Airlie , Daniel Vetter , Guenter Roeck , upstream@semihalf.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 26 Sep 2023 07:01:22 -0700 (PDT) On Fri, Sep 22, 2023 at 8:34=E2=80=AFAM Lukasz Majczak w= rote: > > As drm_dp_get_mst_branch_device_by_guid() is called from > drm_dp_get_mst_branch_device_by_guid(), mstb parameter has to be checked, > otherwise NULL dereference may occur in the call to > the memcpy() and cause following: > > [12579.365869] BUG: kernel NULL pointer dereference, address: 00000000000= 00049 > [12579.365878] #PF: supervisor read access in kernel mode > [12579.365880] #PF: error_code(0x0000) - not-present page > [12579.365882] PGD 0 P4D 0 > [12579.365887] Oops: 0000 [#1] PREEMPT SMP NOPTI > ... > [12579.365895] Workqueue: events_long drm_dp_mst_up_req_work > [12579.365899] RIP: 0010:memcmp+0xb/0x29 > [12579.365921] Call Trace: > [12579.365927] get_mst_branch_device_by_guid_helper+0x22/0x64 > [12579.365930] drm_dp_mst_up_req_work+0x137/0x416 > [12579.365933] process_one_work+0x1d0/0x419 > [12579.365935] worker_thread+0x11a/0x289 > [12579.365938] kthread+0x13e/0x14f > [12579.365941] ? process_one_work+0x419/0x419 > [12579.365943] ? kthread_blkcg+0x31/0x31 > [12579.365946] ret_from_fork+0x1f/0x30 > > As get_mst_branch_device_by_guid_helper() is recursive, moving condition > to the first line allow to remove a similar one for step over of NULL ele= ments > inside a loop. > > Fixes: 5e93b8208d3c ("drm/dp/mst: move GUID storage from mgr, port to onl= y mst branch") > Cc: # 4.14+ > Signed-off-by: Lukasz Majczak > --- > > v2->v3: > * Fixed patch description. > > drivers/gpu/drm/display/drm_dp_mst_topology.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/display/drm_dp_mst_topology.c b/drivers/gpu/= drm/display/drm_dp_mst_topology.c > index ed96cfcfa304..8c929ef72c72 100644 > --- a/drivers/gpu/drm/display/drm_dp_mst_topology.c > +++ b/drivers/gpu/drm/display/drm_dp_mst_topology.c > @@ -2574,14 +2574,14 @@ static struct drm_dp_mst_branch *get_mst_branch_d= evice_by_guid_helper( > struct drm_dp_mst_branch *found_mstb; > struct drm_dp_mst_port *port; > > + if (!mstb) > + return NULL; > + > if (memcmp(mstb->guid, guid, 16) =3D=3D 0) > return mstb; > > > list_for_each_entry(port, &mstb->ports, next) { > - if (!port->mstb) > - continue; > - > found_mstb =3D get_mst_branch_device_by_guid_helper(port-= >mstb, guid); > > if (found_mstb) > -- > 2.42.0.515.g380fc7ccd1-goog > Reviewed-by: Radoslaw Biernacki