Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1496254pxb; Wed, 10 Feb 2021 09:36:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3ii06NfbopaeJvFTRfzbXhE+WS2e1yYU4XBzXmlzJD7ZOiq9O9679gEdaQLd/e+OBDh3R X-Received: by 2002:a17:906:3916:: with SMTP id f22mr4023071eje.328.1612978569485; Wed, 10 Feb 2021 09:36:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612978569; cv=none; d=google.com; s=arc-20160816; b=sYaSbOuE09wT3u5OVkcbVkUpbhOULqWVD8J2QMBNKQJkWR7X4KSO/2bi9Giy/0kB42 o5X9RAWnHfMn0yl6ipsAEv3Yk+Oby0gomvNSscE9jbSOo1EdwQl/fh0+uTiuXe01aL7y 4O/N6w1TN3v0B/OwukgVYgBGJ9cqgTJ0RM9r2cGlgQVYpcD23stPfo2eg6+UND4fzhPc fW7tmixV+QdWQ/QxfsJOM71ez66eoCU4/QVpPhaiNIm+ZQkcwto0BWGG1+2RyowEgOcG DyhX/n9Qe01iN6H9FFO8lYRsUo85ILOAg/ia+XUgvyBdCSu/iAt61u2oj1ZH+0vzejjk BOIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=r3TD1VAfUO11hF9aR+MVS7dpwQ4XHZyMR7TiZnGBl0g=; b=iqVM8oErbtfqCBoBEqvxIpZkAycR7emnQaEvMqT19j5OAlPTmcb7GnA4FyUEdtmdpr UJy/OiO4kSBZDz3C4rRThu6+TMo9k0Otk2cOGFmt4e7cU+3YLvsQsnz9N4Eybc/OIxoB pOjMihIzfRLjPKHE5RCThctL9ITmcg4+EKNQp2pul3hxi73TqvXOWWQs39AEy5FY2m13 SckPxWRwHNvUtZ5oH3Tr5CZys6Qtf4nqmSopksWrM8RbSu9EgMh+/Sh4mlR5uf3guXcU gmeU5dZ4CTZFa9y9c8jsNHVmAGuZBEzq9UPcdnUvQfuTh260TScxWleA0cUYV0sWQuzD zDow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@beagleboard-org.20150623.gappssmtp.com header.s=20150623 header.b=JFoezMNI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds7si2148228ejc.212.2021.02.10.09.35.44; Wed, 10 Feb 2021 09:36:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@beagleboard-org.20150623.gappssmtp.com header.s=20150623 header.b=JFoezMNI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232565AbhBJRfA (ORCPT + 99 others); Wed, 10 Feb 2021 12:35:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232841AbhBJRbo (ORCPT ); Wed, 10 Feb 2021 12:31:44 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EA25C06174A for ; Wed, 10 Feb 2021 09:31:04 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id o7so1690138pgl.1 for ; Wed, 10 Feb 2021 09:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beagleboard-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=r3TD1VAfUO11hF9aR+MVS7dpwQ4XHZyMR7TiZnGBl0g=; b=JFoezMNI7Nb31jHhwYFqP7nmDWA7073Dh5KxzGSxmXniyuDG8tb0hMnQZEikXrqcJH DDuDNhIFh51Fh9LBHlwW5xgjdKp31CMNmxmYCPehx6dfgEMjAZDlhgQb1hMT/VfBNSgQ F6SIOWzti1rHnvPYZxrGB5VZEpYxgSNE48nZds/Pe8gB6qM/rOUPzDdCh6/kIZ090IZa WKMx8bkWnRIxSvqvQ6uqNQbyNvVaABOyxR2Fb3tFOGl173gPgOmgwvRR37qWbINyZWjV DMmnSU9EqiZXbzQiHNb1h6Rea5HvCAi/tRLydSOJobWAz93H+AcLeAVX8wdrkksf2kT9 YjqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=r3TD1VAfUO11hF9aR+MVS7dpwQ4XHZyMR7TiZnGBl0g=; b=NRYorml4a2/CakcnFWkVyeT0a94VQP6suTtki5G7lfC40GOyn+C8I8k4B9vQ/2rD8R iw/vi8hTeZ3w4p+t15oipdggdGezc9kKBzgg8y0rVfYhbL80XuYl3/FP6Ait1vsByjnt 0gBwu1LijcmDy1ynRKEXQe54xx/d226JFYOFJx8tRE4pYZsjMQDs2BYkMTQmKvqI7MAN w+e7FNdw6jzGdNHqYgwXJgjOgWVHkj34BGzOvl8MAvLa9Fhp9d1vOQZi0N61V8v0New/ ZVyIzX6NkeQlrD40J7H6/7q20ekJ4pJFPy3FFby5oKNv+8mzp0SRnSgJdb/q900bAv4b XFPQ== X-Gm-Message-State: AOAM530BgpZ/J8ejux0/0S5iE5pXVlbXeh28Sevy0aFxV4xIcMJ4qzdM AD5yoX9AFc2vwLN78jyBc3BNw9V4J9lw4Q== X-Received: by 2002:aa7:92c6:0:b029:1cb:1c6f:c605 with SMTP id k6-20020aa792c60000b02901cb1c6fc605mr4179151pfa.4.1612978263556; Wed, 10 Feb 2021 09:31:03 -0800 (PST) Received: from x1 ([2601:1c0:4701:ae70:7b19:df69:92d6:528e]) by smtp.gmail.com with ESMTPSA id 68sm3153793pfg.90.2021.02.10.09.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 09:31:02 -0800 (PST) Date: Wed, 10 Feb 2021 09:31:00 -0800 From: Drew Fustini To: Andy Shevchenko Cc: Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Tony Lindgren , Alexandre Belloni , Geert Uytterhoeven , Pantelis Antoniou , Jason Kridner , Robert Nelson Subject: Re: [PATCH v2 2/2] pinctrl: pinmux: Add pinmux-select debugfs file Message-ID: <20210210173100.GA178344@x1> References: <20210210074946.155417-1-drew@beagleboard.org> <20210210074946.155417-3-drew@beagleboard.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 11:56:49AM +0200, Andy Shevchenko wrote: > On Wed, Feb 10, 2021 at 9:50 AM Drew Fustini wrote: > > > > Add "pinmux-select" to debugfs which will activate a function and group > > when 2 integers " " are written to > > the file. The write operation pinmux_select() handles this by checking > > if fsel and gsel are valid selectors and then calling ops->set_mux(). > > > > The existing "pinmux-functions" debugfs file lists the pin functions > > registered for the pin controller. For example: > > > > function: pinmux-uart0, groups = [ pinmux-uart0-pins ] > > function: pinmux-mmc0, groups = [ pinmux-mmc0-pins ] > > function: pinmux-mmc1, groups = [ pinmux-mmc1-pins ] > > function: pinmux-i2c0, groups = [ pinmux-i2c0-pins ] > > function: pinmux-i2c1, groups = [ pinmux-i2c1-pins ] > > function: pinmux-spi1, groups = [ pinmux-spi1-pins ] > > > > To activate function pinmux-i2c1 (fsel 4) and group pinmux-i2c1-pins > > (gsel 4): > > > > echo '4 4' > pinmux-select > > ... > > > DEFINE_SHOW_ATTRIBUTE(pinmux_pins); > > > > > + > > One blank line (existed) is enough. > > > +#define PINMUX_MAX_NAME 64 > > ... > > > + buf = devm_kzalloc(pctldev->dev, PINMUX_MAX_NAME * 2, GFP_KERNEL); > > You have to (re-)read documentation about Device Managed Resources. > Keyword here is *device*! Pay attention to it. TL;DR: misuse of device > managed resources here. > Potentially memory exhausting (local DoS attack), but see below. > > > + if (!buf) > > + return -ENOMEM; > > ... > > > + devm_kfree(pctldev->dev, buf); > > Calling devm_kfree() or other devm_*() release kinda APIs is a red > flag in 99%. See above. Thank you for reviewing and pointing out this issue. Do you mean that I should not be treating these buffers used in the debugfs write op as belonging to the pin controller device? I have looked through the kernel code and I realize now that I don't see any instances of devm_*() being used inside the read or write op for a debugfs file. As I consider it further, devm_*() does not seem to make sense as I am creating the buffers only for temporary use inside pinmux_select(). I'll get that fixed in v3. Thank you, Drew