Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp258383ybl; Thu, 15 Aug 2019 16:51:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9l3Rw7THnohvAQjA1MIa6f2rveiHfw8S8bdyYWVUAgIQTmIQ05AAkCkvL+KiTCk5h2iBl X-Received: by 2002:a17:90a:b30e:: with SMTP id d14mr4287510pjr.26.1565913113442; Thu, 15 Aug 2019 16:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565913113; cv=none; d=google.com; s=arc-20160816; b=JhD2Ahvp3UCxjFxjpG7dmKopEb8xqbO816OCRoD91OA3iP+W/N03NjBmZ9FN/A7yt0 hD9yHrg23PmsYFuDWvaxwAOD/i6s0iqk4tzpstpnApYEgSID/2KAwTFLOiQkSWNrWdZP MLQ+x9awS8VEjFiCbJmu6MRU7I3YyeaCM0Ojx4BQfsEd5yGBBg9BEQh5DUUpnsrRQlUu KV7t37w6tLSSaF+JlcRa72NXmr5ZO2cKk7MB1i0qYy0ZKw7w0jWN8/d4v0ROCbIPeiDu o6IY5nzE7xtFcQCwKZzCaRmfrPUXOIHLGIvNYSWutAplDOYaPHSO8k6A47rhi93cO4xH y/oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=gh7bsGYbNQoYyg4yGUT9u/g5lRriXJz8oS4IHQgucXk=; b=VKi2l8X3/wy0iqFf06fpoCcvk5VBOhYG5gYr85be4dlhjT5dUnmCIJipD1jxVGkxG3 2SctjijaBOmZl+dgi4aGFpiAmXwnH+/DO/ZofHgoQbrn57bAA6ztitTH2d8akHar7sSD Hyyy5PVHA5C+/ZucZwKeFITBZqhb0bVbwIeggmA4MQRO00Dv77fBW63IrJwArPwRLFiV mEmlCy1IEXvJNPmhY9OfOM79SOYlkWNZz5Gi2btizanx0U+1ugeBPv2J7wMaS/wkhq4u l/EzDjnILplGxYGhke4yQvJALuq20V1Djdn0e07IvjL++ZUQ7W6+KIuDQ/gQ2MIVzdKs 8BJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=B0kp+i3v; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i187si3096317pfe.21.2019.08.15.16.51.38; Thu, 15 Aug 2019 16:51:53 -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=@googlemail.com header.s=20161025 header.b=B0kp+i3v; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387465AbfHOWcI (ORCPT + 99 others); Thu, 15 Aug 2019 18:32:08 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41928 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731783AbfHOWcH (ORCPT ); Thu, 15 Aug 2019 18:32:07 -0400 Received: by mail-wr1-f67.google.com with SMTP id j16so3582144wrr.8; Thu, 15 Aug 2019 15:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gh7bsGYbNQoYyg4yGUT9u/g5lRriXJz8oS4IHQgucXk=; b=B0kp+i3vDugvxV0jJjXT52DgeBzCxYP3h7rPFg3bUauVTBOUAiKnHGahD1mSo5s5Vi jRBpUNVk4+WGpOIbt8rViffu4pQ2wLQisE5EKRHc0t9FGQMMy0ToCU3S77JXON5J4Aui sLrm5qqGp1jseuH78hJeHd05gwlf2fjjyE1gfCnMRo+2u8cvNhYvMhv5NHuhha6N0GIO bOkWEK75QdwtJ7GhTKBrFClOkBC7AuaTlnR57Yem1SinQRgJvQ2ZTi8D1qfhtlMJtBW0 jUj23LiUeP+qj+WgMtOoHX/OlOOX7GzMaC0uvV3MC+USXqUSk4OYJv0IB2mnwsFRvwYW nlMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gh7bsGYbNQoYyg4yGUT9u/g5lRriXJz8oS4IHQgucXk=; b=F44MwUbMPJWF28NUfsJky92/54qtLaxKACWWHQejmXpMJjDOsEJYg/6AOnIeQs2NGG 00xRhKKomTXUCTVFkmaizJJO5NZ8YgEuvAOs/t8hwTXQaxMwkIrKkBXjkCYSBTICZQ1o Q2Ee/SWOo9p9IDUDDHA47utTYpZ+YB4VpXRusI/1+jbH15EcFpKu6OnS0fsIFC/4cG4n cA+BBCVmNtEIWCj1m2kQVEUyozi1qHV19tDSka8osByLMwlsgERyLqebX0vPRdNZdl/J 67X73wXxWfa2AuHzEQQflbBjBGiHGC93ctS8sJW+VZa056vPkDtxZwO8MNQCisi12+u9 lHcg== X-Gm-Message-State: APjAAAW2bkg7yW1REfqrpTydSCpWQEp2EYHFlxDW8qyfG130Yq5cZ38X 58UaGKVmxhYCX3MgdMMDYjWhkH/I X-Received: by 2002:a5d:4a45:: with SMTP id v5mr193560wrs.108.1565908324656; Thu, 15 Aug 2019 15:32:04 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133C1F600F17406154CCE0537.dip0.t-ipconnect.de. [2003:f1:33c1:f600:f174:615:4cce:537]) by smtp.googlemail.com with ESMTPSA id c15sm12146513wrb.80.2019.08.15.15.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 15:32:04 -0700 (PDT) From: Martin Blumenstingl To: linux-clk@vger.kernel.org, sboyd@kernel.org Cc: linux-kernel@vger.kernel.org, mturquette@baylibre.com, Martin Blumenstingl Subject: [PATCH RFC v1] clk: Fix potential NULL dereference in clk_fetch_parent_index() Date: Fri, 16 Aug 2019 00:31:55 +0200 Message-Id: <20190815223155.21384-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.22.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). 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). 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 names") This is meant to be applied on top of v5.3-rc4. drivers/clk/clk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c0990703ce54..567a044a368b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1632,7 +1632,8 @@ static int clk_fetch_parent_index(struct clk_core *core, break; /* Fallback to comparing globally unique names */ - if (!strcmp(parent->name, core->parents[i].name)) + if (core->parents[i].name && + !strcmp(parent->name, core->parents[i].name)) break; } -- 2.22.1