Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp555403ybl; Thu, 15 Aug 2019 23:50:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1FkPY8i6rSP+vgz353JSb7F2ibimjEcMvpN5Re8SlUjsCu+sUzLTwqM7QqjL+iEkdvzXV X-Received: by 2002:a17:90a:bf01:: with SMTP id c1mr4923218pjs.30.1565938227819; Thu, 15 Aug 2019 23:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565938227; cv=none; d=google.com; s=arc-20160816; b=Xcb/jVH8ooADO+iu6IIVPZ69kHh7iapKl2fMEl/p3gyM58aBwhYcoHaUQ7n8/Uahcp STTGjEZOfAKsbMcCUalQgtYzU5oYk6FUQCUxLq44zwh85ZPZoxNwfeN2vgkPaZRJ5O2b 2rAIcoX+tt5CtkAyN1yAeswcXx7OZTvK4HBx6QFjxu5UcM/8iF3RZq9pbErlg2jjQDlP IAPtXc30TQ90KSQK1MaIYpm6X/uOXCkFtUX6aQZiNb83tfa56FRCHQRm3BZcF0rdTTHz Shcanrav6QvGx9dubssI8P6BxcFsa6o9zFNEOD5hYxvfthUlwshRj4sinBz4pDitjk95 XtkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=69UIcMbarjhdrqblJ4LWv1FLIeOiPNtNFw7aGmbQg8E=; b=X2e0HB8cO/0oREriMHsafvQEW4P7xchBYmvJ21F8rR5E8tfqLUobQwtOCYTjGF8P69 nuhG96WAEh0q9SIveCLgJV8OkmIaygmqAEPqRJBYNsCF1fAJocAcbEkQjrsI/AEBCe4m 2gm+eZurSbHgBTRfVeZi8EQxGo0cYZ4vgb3wf3uhN3DLmuBEFUhsCaxIMoQQuchsakfF 8eZ0uC8uiddxy8u4R4wcyPVLTYE/UT18TN0rGRyBxuUuUJPWZnC9t4/sRo7MSdQ70Yy9 ARhrDSH7PZVidWr6t2hR/by0p+wuol8UijNi7zIAvSorvMdUYkAdERFPDsINpJA3VKKq qrRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=iRWDMDDS; 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 i188si3708406pfe.96.2019.08.15.23.50.12; Thu, 15 Aug 2019 23:50:27 -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=iRWDMDDS; 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 S1726903AbfHPGsV (ORCPT + 99 others); Fri, 16 Aug 2019 02:48:21 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:34275 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725945AbfHPGsV (ORCPT ); Fri, 16 Aug 2019 02:48:21 -0400 Received: by mail-ot1-f67.google.com with SMTP id c7so8816699otp.1; Thu, 15 Aug 2019 23:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=69UIcMbarjhdrqblJ4LWv1FLIeOiPNtNFw7aGmbQg8E=; b=iRWDMDDS+1mIRq4pdzsc1IXCplD9aAgt5nH0d0+crjiD+5WwkaPqOQwcmNKlkagwra 2bbBFfT3TWETYTjOnmcpGiPwO4/nkxg82WPeubDIo8mzrc+ygLebn/UgnUdBLInhN7x6 eccwLkDZ9B9O9kzHV1EiXK4txN0nS2Wd0ERoSP5wyMKicgp+q6LnKF3XaZIL0xcytyeQ hM+PJgJAMtf2hkKHycruU1nkcGuh+Qp4wLZcLi1WTGXrgcSbYixnaicsfqg4CIDW54SD OwE9QOE3d2ZSc9mJ/oPMWqn8k7IOqym09uKk+fUCujCbZFoldjha46XqPBsctqUMJ9S2 X+lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=69UIcMbarjhdrqblJ4LWv1FLIeOiPNtNFw7aGmbQg8E=; b=GtsL17dBnD1wSjwOxJcQt9NrBB5n57AnyIvLWfMk2KkMXZd9VLoqZRT3S3VyTqd9nn mJcbeUHt4NI5i2lJlgSXzmbQIGCnNXeKbRRW6gvfAqa/1c+paAHcuZ2UaHwTEQzQq1PI ewB+Do0xMZwjwSwVjKYSO93t0VmOY9cZRZFu/J+ea6TSrDT0+lgK7xazNiTz5Nif8rjF 3r1f9jLSuYvuKy8LeFJOLf3R33HEHxTG1bXmBpkzwegjluw0W1J/EeiUv3t54+wT9M39 X+TObWfo63lNsHjfG+GWvXVgE0jV/6BUxBulsFTswMFv/C5MvQFyrXLU6odcVdbRx0on Xnaw== X-Gm-Message-State: APjAAAWh/PjKQCJ7hTbo+kjFCFBkmMQ5vMCxnGFrWE/SuTs/fKwG8HYe 2XPIPe6Q1CTnKzzW4bjvbdTqf7ho/fFhsC/7i0w= X-Received: by 2002:a9d:1d5:: with SMTP id e79mr6440340ote.98.1565938099783; Thu, 15 Aug 2019 23:48:19 -0700 (PDT) MIME-Version: 1.0 References: <20190815223155.21384-1-martin.blumenstingl@googlemail.com> <20190815232951.AA402206C2@mail.kernel.org> In-Reply-To: <20190815232951.AA402206C2@mail.kernel.org> From: Martin Blumenstingl Date: Fri, 16 Aug 2019 08:48:08 +0200 Message-ID: Subject: Re: [PATCH RFC v1] clk: Fix potential NULL dereference in clk_fetch_parent_index() To: Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, mturquette@baylibre.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Stephen, On Fri, Aug 16, 2019 at 1:29 AM Stephen Boyd wrote: > > 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(). > > > > 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. > > > > Ah ok. I thought that strcmp() would ignore NULL arguments, but > apparently not. I can apply this to clk-fixes. at least ARM [0] and the generic [1] implementations don't I did not bisect this so do you have any suggestion for a Fixes tag? I mentioned two candidates above, but I'm not sure which one to use just let me know, then I'll resend with the fixes tag so you can take it through clk-fixes Martin [0] https://elixir.bootlin.com/linux/v5.2/source/arch/arm/boot/compressed/string.c#L91 [1] https://elixir.bootlin.com/linux/v5.2/source/lib/string.c#L356