Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2530667imm; Tue, 4 Sep 2018 06:08:13 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb70RAqF7vcYk+I02PHQyT8fqduQIZZuLlVMcgKAThDOHOzgpiVRWx5CiFLMoeXWy9hwdvB X-Received: by 2002:a65:6398:: with SMTP id h24-v6mr31469080pgv.245.1536066493866; Tue, 04 Sep 2018 06:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536066493; cv=none; d=google.com; s=arc-20160816; b=n0b5H9hNmzk4eVLOHZc3M7IhNM7HVIzoUVHBj3fFRCbgnjn/tbiEx0Y5kWbEvfX05X QXk6vbDAdaQV1bSX+SiM2wvYHsjKH5BdihNXoQ6iw/augd5Mau8ToXeyPc+AUL3KDBex D7ruKIdpB1SacWxUcIFxhiwRHfBMmeYWvEYqqcUptSnp83sANcGacLmBdKBJyrT6p4gC QnXJB1AS4qzjMzryhKirIJ0th6PB374NVZXw3ciSS7EwQmKLoFbgKOdv6cZxSGWD3lIr nkg4DQ7qCgXb0Q8mBniLNJ64XGNBaY6eY4cHQdXc3pnDySwHlHp2ZOZEq6x638iCCwXh pvyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=1Upe3TYatnxKCqeXoi9nTOeWzDnbeMRTAHDOO8UjGpY=; b=q6JWhZumjpTLi1r7dt3iKm2KHzPHuG48iXbQiIYGQahuEFfTMOp8mjm2fhPVSlXgjB MqGl9TrlS/kdnlNMdxxTaqeneJOCOfDdWB6gQGJ5ULQAoXnxjnQqNkX16vLztz4/ZHMA CA7MBOlKs+F3QBLp8a9Nu0qCfrwzit7tfApNIOdmIl6pp3an0GYcAAlik9ztloTziVsn qu0ipSKO25ecq3OmAZoxJKhMmwhaGwGcxyFlvdAmAADu6TvI090Lr7eS0deQOcMm3lxN suFNnpiS3b+ZdtvVI8ZeMhRtGVurSvB7LhazxipB7jm/hu070E4GzKg4/VbRECAbeqp6 3cEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=lxYfFrx+; 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=fail (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 e5-v6si21242808pfg.258.2018.09.04.06.07.58; Tue, 04 Sep 2018 06:08:13 -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=fail header.i=@gmail.com header.s=20161025 header.b=lxYfFrx+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727502AbeIDRa4 (ORCPT + 99 others); Tue, 4 Sep 2018 13:30:56 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:46381 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726355AbeIDRaz (ORCPT ); Tue, 4 Sep 2018 13:30:55 -0400 Received: by mail-lj1-f196.google.com with SMTP id 203-v6so3045359ljj.13; Tue, 04 Sep 2018 06:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1Upe3TYatnxKCqeXoi9nTOeWzDnbeMRTAHDOO8UjGpY=; b=lxYfFrx+Sd5s6bUT0pj1/lbk5D/YTMSHDZtHUXNoDF5eZuEMRkqhTHuX6i1vFGdgfd nk6rcRclf1902NvvIA9QKz+wUY8XSqEKS5bxIHMQTqKWjPCVqx84i3PIxFdmfqKRQZc9 gMlsiUv4Acq7N/QOr/dNy3xbnnAev92hzzlREMcZ6H4t/AQ2Bbvr0uQd1BD7I+tpVHtS FS5HFOplEje5Riq2e4QTfjg0amSseSbTid8ggi2yXzYMkWcSzI08KI8WklkdZW1HZ7LF f+I1YiyZuiVzn5UFM+tEwssF919ZiwxWJ+nAoxupVuy6PBRc2nRPGcHRWQVDxdT6lGy5 vWsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=1Upe3TYatnxKCqeXoi9nTOeWzDnbeMRTAHDOO8UjGpY=; b=Py8OnTVlCadpCqe1hfy1bCUF8L8Kf0+gFzD9PQfdBJ0sLg6piU0WC2Dnlkv22EIjsF FokvzmydB653mHIqhZ9iihH0Arc8gIKNpmtLxl6UHI2vjaYLZn+wl/2DiC6nSDHtbMiE qq96fr36mZItwnsG0ZKhOgyagmfa+hB/M9a0HOSudAM4vnwM372VaJQ6nhXGzPd7xy1M CfzYk/Idu4DSSWqBEw4VwvjkcoDSeiB6Z55bSPVhlVasPic5Y9xC16F2YBMCRTWHVtFI biNm1eMuqPjiPl2p6b67glYSR1WlJ+WcMpzSY7zM+ulhVwMmwycltKRrzxatZKlUnUmV lEMQ== X-Gm-Message-State: APzg51BY1trPgwEl/ZfFNLaPuo3wTzsyurDjYRLSssFijcQd5iFTp7ea k+SjUA3+2secuWPLzFNh+HM= X-Received: by 2002:a2e:29da:: with SMTP id p87-v6mr19670511ljp.12.1536066350159; Tue, 04 Sep 2018 06:05:50 -0700 (PDT) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id y85-v6sm4170586lfi.46.2018.09.04.06.05.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 06:05:49 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1fxB1p-0001gs-Pm; Tue, 04 Sep 2018 15:05:57 +0200 Date: Tue, 4 Sep 2018 15:05:57 +0200 From: Johan Hovold To: Rob Herring , Greg Kroah-Hartman Cc: Frank Rowand , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , CK Hu , Philipp Zabel , Rob Clark , David Airlie , Ulf Hansson , Josh Wu , Boris Brezillon , Doug Berger , Florian Fainelli , "David S. Miller" , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Samuel Ortiz , Sebastian Reichel , Martin Blumenstingl Subject: Re: [PATCH v2 0/9] of: fix compatible-child-node lookups Message-ID: <20180904130557.GT28861@localhost> References: <20180827082153.22537-1-johan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180827082153.22537-1-johan@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, On Mon, Aug 27, 2018 at 10:21:44AM +0200, Johan Hovold wrote: > Several drivers currently use of_find_compatible_node() to lookup child > nodes while failing to notice that the of_find_ functions search the > entire tree depth-first (from a given start node) and therefore can > match unrelated nodes. > > The fact that these functions also drop a reference to the node they > start searching from (e.g. the parent node) is typically also > overlooked, something which can lead to use-after-free bugs (e.g. after > probe deferrals). > > This series adds a new helper, similar to of_get_child_by_name(), > that can be used to lookup compatible child nodes, and uses the new > helper to fix child-node lookups throughout the tree. > > This is related to the fixes I posted about a year ago, which addressed > a similar anti-pattern when looking up child nodes by name. Since it > took me more than a year to get all those fixes into Linus' tree (one > fix is still pending), and as these fixes depend on the new helper, I'm > suggesting that these all go in through Rob's or Greg's trees. > > Alternatively, the helper could go into to -rc2, and I'll be pinging > submaintainers for the coming year as well. ;) Rob has gotten the helper into -rc2 now: 36156f9241cb of: add helper to lookup compatible child node so feel free to pick these fixes up directly for 4.19-rc or -next, whichever you prefer. I've been able to trigger crashes after probe deferrals due to the use-after-free, but this seems unlikely to be exploitable. I think Rob will be picking up any patches that remain by the end of the release cycle for 4.20. Thanks, Johan > Johan Hovold (9): > of: add helper to lookup compatible child node > drm/mediatek: fix OF sibling-node lookup > drm/msm: fix OF child-node lookup > mmc: meson-mx-sdio: fix OF child-node lookup > mtd: nand: atmel: fix OF child-node lookup > net: bcmgenet: fix OF child-node lookup > net: stmmac: dwmac-sun8i: fix OF child-node lookup > NFC: nfcmrvl_uart: fix OF child-node lookup > power: supply: twl4030-charger: fix OF sibling-node lookup > > drivers/gpu/drm/mediatek/mtk_hdmi.c | 5 ++-- > drivers/gpu/drm/msm/adreno/adreno_gpu.c | 5 ++-- > drivers/mmc/host/meson-mx-sdio.c | 8 ++++-- > drivers/mtd/nand/raw/atmel/nand-controller.c | 11 +++++--- > drivers/net/ethernet/broadcom/genet/bcmmii.c | 2 +- > .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 12 +++++++-- > drivers/nfc/nfcmrvl/uart.c | 5 ++-- > drivers/of/base.c | 25 +++++++++++++++++++ > drivers/power/supply/twl4030_charger.c | 5 ++-- > include/linux/of.h | 8 ++++++ > 10 files changed, 68 insertions(+), 18 deletions(-)