Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2654175pxb; Thu, 11 Feb 2021 19:41:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxffIAVYk9yQGIMcZQ4KdIknecVNvDec+OIG5IgtVOUC/sPtfTvYLTHZhRO7DI0KU9juPh7 X-Received: by 2002:a17:906:c444:: with SMTP id ck4mr1059251ejb.156.1613101303074; Thu, 11 Feb 2021 19:41:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613101303; cv=none; d=google.com; s=arc-20160816; b=Bp3I0SHdRGcJpK8frmIyVwqvsWtRWgbhQxQsQrCuvoOEkAqHeMM0iFtJ2IKkyOmpSX nQLxHGOG7f6Tcw8Sg8vB7m5LkVhoJs/JLw0L+XgIwdKqBdhf94j1L308gITBdsJ5pPev 3LUDfe1+tAaKEMrFFAQvA/A9Af74hNXMkBSFvKLeua/gb47an1TSOlu1f3tB7JhH4H6H E6phwpZ5Apnhkzjbw+6bVl7R2uKFEinRHW44ba3V6C4oj1ao5zTEjp8QM6Ip2OVIV0v5 t933OclSr9QJh35RxQ7BAcPPwkEKbw5noFAfUJixVuLUsC5FPFsOAHOtori4AFRF3edh 3S/w== 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=9pfqimY918txMekV6200j2kXsBs+f5cQJygUowRP0KQ=; b=FZ96bdF7jnkjZe7bxLfJiHxVwxV4SjA1bKBfvI3HrQPa0pXHqtcIhNKH050TSKJuwA KWOvCXMXsi0BsAMhvQ4NWVuYKgBK/wvRzoitKmvwjeHivx92FjfWGQWgO/M8hXd4MWhY a9eU5DXzKF2d5YGjl8OhMroCUWvEOtmhfJsLOtbU/juXaxmLrO30dccmLivqTOTNzkmj JslYJFh1uqWD5bQn6CIbCvjTpI24S+EZ8PSO1yQi4YTUF6WWdqm4fuNp0/+zQz6Vd8AT 0A+UcxkvUl89mR9T2BSAzTV0kumKxAoaEnR3FS/WdfVSVwZodvW0eChN/MoC+6rIpZRu zH9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@beagleboard-org.20150623.gappssmtp.com header.s=20150623 header.b=Br7Dcgxh; 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 e18si5697516edz.446.2021.02.11.19.41.19; Thu, 11 Feb 2021 19:41:43 -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=Br7Dcgxh; 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 S229538AbhBLDkC (ORCPT + 99 others); Thu, 11 Feb 2021 22:40:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbhBLDkB (ORCPT ); Thu, 11 Feb 2021 22:40:01 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A421DC0613D6 for ; Thu, 11 Feb 2021 19:39:21 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id 189so5004175pfy.6 for ; Thu, 11 Feb 2021 19:39:21 -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=9pfqimY918txMekV6200j2kXsBs+f5cQJygUowRP0KQ=; b=Br7DcgxhhjHydvnpOAxSeYaNdpX8E+TNUdaxgJpW8f1JLqjn3FjsES8NPybkQiSv47 JP1fYHObl3y/WvHVUzzr2gc/k2a4F/hNphRt+68cLzWh7wFEP6UXlfB7l1qtuKQHCKeM 3lwMUosT426B+cJOeYVYrd5fmF5OYoNYHPV2qRNM37nPEmeY21cQLDWt61I1uiaJr2ZJ Mwr872PJW9XjzkGZW8PgFTv0c2XG5BoIMwvFrOd0m+HI/tPDUPjfaICk0g1CIXqKf2p/ NOgGHRZYxIj0jhtV+Sh6qCwI1w1dsQJXt6cmSuOlITUKRls6jOxR8qEkmGDicFVAqx6n NeeQ== 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=9pfqimY918txMekV6200j2kXsBs+f5cQJygUowRP0KQ=; b=E5FQ5yS9mPaClru6Eu/sgYwQdnJIqfaSs71//m06RmvOmlOXgPW/ha3lOuZlLydXjx VAV1MhNJkhCK2YMqvzkvV5NGGvizeS2qjESJLdpU0L1jBKISf8huX4lURwwshx94XTPv uXOmvD7AmH3j6E2a2ynKQpA1+j+epul9kaA5N43cQgeHRN+20/V6AdZc6t4mcAQ3Olpo +S0urDacVobbcPfpMbByQm06L2Gql/JoLeT25qjI1HRZsan/VxjFdx2qMSkaybl6lBHG AbpIuEkozQRhCoAxp4mowjgXW9hntAzeWy4teAb1ls3Lw2XHrkRxYMb734EVVaPEgeTO R1Fw== X-Gm-Message-State: AOAM530uoWUtArITKH7lzBlb7woCNS9CMAqln3Oz17uui4G1xDGcKfsf Yksgf7CthiTkxK5RrRWPvoXWhQ== X-Received: by 2002:a63:c10f:: with SMTP id w15mr1252144pgf.99.1613101161204; Thu, 11 Feb 2021 19:39:21 -0800 (PST) Received: from x1 ([2601:1c0:4701:ae70:3a7f:bbfb:1664:2a63]) by smtp.gmail.com with ESMTPSA id n15sm7290212pgl.31.2021.02.11.19.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 19:39:20 -0800 (PST) Date: Thu, 11 Feb 2021 19:39:18 -0800 From: Drew Fustini To: Andy Shevchenko Cc: Geert Uytterhoeven , Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Tony Lindgren , Alexandre Belloni , Pantelis Antoniou , Jason Kridner , Robert Nelson , Joe Perches , Dan Carpenter Subject: Re: [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file Message-ID: <20210212033918.GC347396@x1> References: <20210210222851.232374-1-drew@beagleboard.org> <20210210222851.232374-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 Thu, Feb 11, 2021 at 11:53:24AM +0200, Andy Shevchenko wrote: > 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. > Thank you for the suggestion about how to implement this. I'll use that in the next revision. -Drew