Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp262484ybl; Thu, 15 Aug 2019 16:57:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzUKynH382+mLNUgdpc5Vsr7BZHwGyFFuUtv89s/9BKWWAbvY8hZfJHvyVrI+pZZnoSOCk X-Received: by 2002:a63:3387:: with SMTP id z129mr2469771pgz.177.1565913442310; Thu, 15 Aug 2019 16:57:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565913442; cv=none; d=google.com; s=arc-20160816; b=Oc3OEcO9f57d6yJCtHVXe4JqIEhBSgoMace+QhdgmKxheRaDQbF2z/cN+G5f/Hq/cl baxnjvd6kfYTw6jr3aOvP0/5cM23m+2tuBMXJRj+gq/j6jEovofICq5yzy0zZvO8TO7/ 8sPn1X7ABBmmBa20g+ub6jL32DSSYi2TmGYChn7lBaEM5nssM5qY7QZ38U3mHY8FJvBe PAjknA4w9UHx0yC0lGSu/eWapg54zHXa3D6W6raXxU1Zo2+sS+aZ/XivwZjj2BektVog 0vACvxotSeqe9oIGit51ZrO6VnA+U8NmOd4Yl27GSgc2VLPz2pcWNZAfzSWJLOM3wlHx SUJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:user-agent:to:cc:from :subject:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=UUdMem/EasFhb4Dfk05FjFveBpohgSiNrTN38IFMTeQ=; b=eTBQYVvXcs9/gmIXChR98ihBRC3rcrGD4ZwEr+pm5X15o4JTON/Zditq2qKio+X9kM sS36zDrQNIifLZMOpPYlFOi85X9f9LFbE1iDBgqdxCHsR+vRQFBfMut57ST88ZYx5pix c8nf4xJnEbhP4W+f9LGHvKG4EZZOQugbPhdaN4RmwN3MQrV3PcF1i5rNyU9IWNI066fn 3x9nk+EjmcbN1Z1NKo5tMIAsH0e05KEUiX2AE3159wBxrVlDX2WuMhyxEaitd69szoGF WEwbJE8lJiKPAM6Oskppj69OLY4FMIM8fR4D1jyoCToMVMCcowKWganjUZWhoijG0T8S yOzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cfJ9mKIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si2695657pgn.433.2019.08.15.16.57.07; Thu, 15 Aug 2019 16:57:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cfJ9mKIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726023AbfHOX3w (ORCPT + 99 others); Thu, 15 Aug 2019 19:29:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:47056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725440AbfHOX3w (ORCPT ); Thu, 15 Aug 2019 19:29:52 -0400 Received: from kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA402206C2; Thu, 15 Aug 2019 23:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565911791; bh=UUdMem/EasFhb4Dfk05FjFveBpohgSiNrTN38IFMTeQ=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=cfJ9mKIJWeIdXMeH4f51/xiWPrnLZ/QFwdEMi7GNTJysZFmqGa5ZBvZnYudct4+Em 0GbVgeMDcVG4oOG5fhnvU9VKqaCIkuYNBl/PQMa9aic7snRGH+hVR/5nLjC9bhOPrn cr/yUJhQunmDeASMSZWRRYmrx6ettOs04pSg5jSQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20190815223155.21384-1-martin.blumenstingl@googlemail.com> References: <20190815223155.21384-1-martin.blumenstingl@googlemail.com> Subject: Re: [PATCH RFC v1] clk: Fix potential NULL dereference in clk_fetch_parent_index() From: Stephen Boyd Cc: linux-kernel@vger.kernel.org, mturquette@baylibre.com, Martin Blumenstingl To: Martin Blumenstingl , linux-clk@vger.kernel.org User-Agent: alot/0.8.1 Date: Thu, 15 Aug 2019 16:29:50 -0700 Message-Id: <20190815232951.AA402206C2@mail.kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Martin Blumenstingl (2019-08-15 15:31:55) > Don't compare the parent clock name with a NULL name in the > clk_parent_map. This prevents a kernel crash when passing NULL > core->parents[i].name to strcmp(). >=20 > An example which triggered this is a mux clock with four parents when > each of them is referenced in the clock driver using > clk_parent_data.fw_name and then calling clk_set_parent(clk, 3rd_parent) > on this mux. > In this case the first parent is also the HW default so > core->parents[i].hw is populated when the clock is registered. Calling > clk_set_parent(clk, 3rd_parent) will then go through all parents and > skip the first parent because it's hw pointer doesn't match. For the > second parent no hw pointer is cached yet and clk_core_get(core, 1) > returns a non-matching pointer (which is correct because we are comparing > the second with the third parent). Comparing the result of > clk_core_get(core, 2) with the requested parent gives a match. However > we don't reach this point because right after the clk_core_get(core, 1) > mismatch the old code tried to !strcmp(parent->name, NULL) (where the > second argument is actually core->parents[i].name, but that was never > populated by the clock driver). >=20 > Signed-off-by: Martin Blumenstingl > --- > I have seen the original crash when I was testing an MMC driver which > is not upstream yet on v5.3-rc4. I'm not sure whether this fix is > "correct" (it fixes the crash for me) or where to point the Fixes tag > to, it may be one of: > - fc0c209c147f ("clk: Allow parents to be specified without string names") > - 1a079560b145 ("clk: Cache core in clk_fetch_parent_index() without name= s") >=20 > This is meant to be applied on top of v5.3-rc4. >=20 Ah ok. I thought that strcmp() would ignore NULL arguments, but apparently not. I can apply this to clk-fixes.