Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2017395pxb; Thu, 11 Feb 2021 02:01:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvCbI1wgZUgxZwS96EFYHtilgoTvxf+HzngYUTkZBGupjFZpyD82fgku2IhL77nxnTgZ+u X-Received: by 2002:aa7:c351:: with SMTP id j17mr7567648edr.261.1613037671862; Thu, 11 Feb 2021 02:01:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613037671; cv=none; d=google.com; s=arc-20160816; b=PuQ4dEcwaVsImGBH/QJVkkyQ6DfUrvtkUpT3eO35Ho39cV3moUetQLyMnLtBIXf9eV gYT0L8eN3kbvF4i60OP0uH0pVVe7sRpiJCY5yxuErBKKob4ZUDP28X7NE0b4Vt9ZM5H9 JOGVX/Phhagag95Yh//ROq7c3GHIRbcZsWoN6QDM/rchqXSGQRPdkbb9uy3cvNgtoDpb B+RsO9EUOZIbFOuhhpc/xDajOZkmO62ux3Tq4yYIFJKPboUYjrSYUea9BvFg/rfxf7T2 Xv8XwFmuozuuHTDDNnTG5LgB5dJ7fwt283SRbvuSQ5TAUVkFGtSMmkOKROYKHy4prQBW /jKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/2/r886KQW4/hmgGlGU/bFt+5s/atopbbN5Yr8MK8T8=; b=lQyf8Brh4Y8Zed5+BySuFBZdlHlBxOPiv2Vxrg8ImpuC6Qwr7Fau06i0NZswx04Hx3 Suh25dvVDniJgCq3E97TK7avHmPmwo7dKtC+5A+pd4X18EwO3MdjTQzc59Ejj2RjUYT6 Xr4mig0WRXsoT/e1yYGPRNetPhTvQ8sU8C92cTT8EgmC5m7fToUWc+9OxqQ1aXzhc2Cq 1zQqkve/K0yCO+NxKC9ZHHuRTbH+tIu03XQwMf5FOICruUzzacFshsdSC9wzQiptzjSi Tq8caO6WpZuOQanugBi7ckpaukUIx0uPPi3w3Vb8nYqLaqhxn0Vi/Me1HitJFQ6SRpCQ 7M2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vQystuV8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si3406622edy.471.2021.02.11.02.00.37; Thu, 11 Feb 2021 02:01:11 -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=@gmail.com header.s=20161025 header.b=vQystuV8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229699AbhBKJ6C (ORCPT + 99 others); Thu, 11 Feb 2021 04:58:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbhBKJyV (ORCPT ); Thu, 11 Feb 2021 04:54:21 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59707C061756; Thu, 11 Feb 2021 01:53:41 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id fa16so3093906pjb.1; Thu, 11 Feb 2021 01:53:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/2/r886KQW4/hmgGlGU/bFt+5s/atopbbN5Yr8MK8T8=; b=vQystuV8OWeUPFQ3fFsiGIqaSCxcNFDVbhkLn8xcohJXWQYYbiqtdKXbckM/D9dXCj fKfz2kijNBYFNr1/O3rZVTte5r+2gb9FoXlFVJ18L1BEtiy1mj0aydeUAFMbUdY+fL3t v56Qrbz5YTHi3tcxlPE6C3GmKyjzFV/l1B8uDD4k8gT4/oXpV4Q+BeLY8RxxionPZtaF JaTGGQFKDYAxh6gZXVQAN+orJ5fbL/1iykRtYV3EueJ0ryiyxDOA4T6mEF/bgvP28BQL hqtTEfVqaVaCV7S/ISIF+VVf6afLIpQwNZADARhn53ecri4gZOZZOhQzsAjCpIiqBmyW 6KjA== 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=/2/r886KQW4/hmgGlGU/bFt+5s/atopbbN5Yr8MK8T8=; b=Aq9eBqAMHcRJ6elRm2ttzu2/U12F1YSeXwhL9h/x1cyXVOg4YDOhDfmaBSzuVeoBnf ekQV1LLmxWHuV4j/zZWFSBTBhu1OkZF8eDtulAQJrMfa8EEeZ26XclqxRCvv503PkAWQ 4fZ0U2r7wdBIE62xzMKH+PIyG+655311OihUAwGHi8XgCySck3nNh1puET36rH1buIHO GyslQwa5UlExzA0blxfnD92b2BjgS65RCd45kPOsHpOLbR6ipdTUFnetg7sRcIRoKwtw a3wSDw5IsHifnHzH37GdZfg+q4jVtqAIbODtHv8zHk6tQfTGNBM0zI9m2UASnINbV7tt RFbg== X-Gm-Message-State: AOAM5316mF4AovNAANe/S4xnFYqF6sNkyNJPjjX3cjmYxJSChAwUCRTx q7x5t8wCD644/K3Y8Eo4zF5CNQPpReTAE/G9wJ0= X-Received: by 2002:a17:902:be14:b029:e1:bec9:f4a7 with SMTP id r20-20020a170902be14b02900e1bec9f4a7mr7208681pls.21.1613037220776; Thu, 11 Feb 2021 01:53:40 -0800 (PST) MIME-Version: 1.0 References: <20210210222851.232374-1-drew@beagleboard.org> <20210210222851.232374-3-drew@beagleboard.org> In-Reply-To: From: Andy Shevchenko Date: Thu, 11 Feb 2021 11:53:24 +0200 Message-ID: Subject: Re: [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file To: Geert Uytterhoeven Cc: Drew Fustini , Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Tony Lindgren , Alexandre Belloni , Pantelis Antoniou , Jason Kridner , Robert Nelson , Joe Perches , Dan Carpenter Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 11, 2021 at 10:09 AM Geert Uytterhoeven wrote: > On Wed, Feb 10, 2021 at 11:33 PM Drew Fustini wrote: > > +#define PINMUX_MAX_NAME 64 > > + if (len > (PINMUX_MAX_NAME * 2)) { > > + dev_err(pctldev->dev, "write too big for buffer"); > > + return -EINVAL; > > + } > > + > > + buf = kzalloc(PINMUX_MAX_NAME * 2, GFP_KERNEL); > > + ret = strncpy_from_user(buf, user_buf, PINMUX_MAX_NAME * 2); > > While this guarantees buf is not overflowed... > > > + if (ret < 0) { > > + dev_err(pctldev->dev, "failed to copy buffer from userspace"); > > + goto free_gname; > > + } > > + buf[len-1] = '\0'; > > + > > + ret = sscanf(buf, "%s %s", fname, gname); > > ... one of the two strings can still be longer than PINMUX_MAX_NAME, > thus overflowing fname or gname. > > As buf is already a copy, it may be easier to just find the strings in > buf, write the NUL terminators into buf, and set up fname and gname > to point to the strings inside buf. You beat me up to it. I was about to comment the same. So, indeed, instead of sscanf it's simply better and faster to do just something like fname = strstrip(buf) ; if (*fname == '\0') { ... return -EINVAL; } gname = strchr(fname, ' '); if (!gname) { ... return -EINVAL; } *gname++ = '\0'; on top of the buf pointer. > > + if (ret != 2) { > > + dev_err(pctldev->dev, "expected format: "); > > + goto free_gname; > > + } -- With Best Regards, Andy Shevchenko