Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp761922pxa; Thu, 27 Aug 2020 15:20:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeHCBT6CEbYSQLv+SWkpguluk8x4ZsajC1/ESv02V2zR+vRdS+YuuzXbKSUw2cp19uFvAJ X-Received: by 2002:a05:6402:7d1:: with SMTP id u17mr21342418edy.48.1598566824728; Thu, 27 Aug 2020 15:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598566824; cv=none; d=google.com; s=arc-20160816; b=UFlixs+3QCmrVCI9OuBVKEvmecsO40m2+sCv+/vL2B3h+PrQqLdOrM3v1ntMmCAc3e 0fKpAla/MP4MSWW4RWzRZfFfGvktjKBvhtk5+3czIwfXq1+bmIQo0QAq7RBS5bSlgVkn VV/GL1i0ObV+YXCH8LfdJ1d34KEoq/i9tWwF0SUc2sLINR4hLKaxntq6EgFZJ3+/8jOa w7riI+NkczwI3mj98rX6HgmxfMPVzRQ5u91QEZZMBNkMr+xJ4UuHy/KfqtsCpsvDL9rz E6fVAaM0K/xmkIj2zaESzum898eDX+WxEfol9TveTWFjmBGZLV/QXoL+G40XJ1c5PAHC 6dkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lLmbzoSbX37WRFYQW3L/1ffMVUDf88bIb2L15ySX4bI=; b=EqmKF26ZnsgOAeGNG1P7qqbpPc14p9WusShcwYlM5Br+06B9vFKFYLlNAsZOaMWLSn ASGfRci01papUysWMMxIRDlk+79YlDhuS7CVEbZ0M8XwPmW0tmZoDdWQt5QWAheLKMZ7 vQvhwyKQL5/jKEHkWM6zbSTq+8sJbpzQ6LDEHrbbNhjyL5OMz80WMsMMekGsZ7nEVS55 ZqbA1Qzj5oOEncxCeyV2hzV7AzHc/WZJomhP3p8lY+iy+orPWgHC2Qxj1m2IhWqcqIwF SgPJJQFw59OIrVqBdQQf0vEhYq3IRob4sWnm6R1Bd5zeBk+TyIeSVWWuMmouZU76WcTo ak4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Sn1Xn765; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si2194511edv.80.2020.08.27.15.20.01; Thu, 27 Aug 2020 15:20:24 -0700 (PDT) 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=@chromium.org header.s=google header.b=Sn1Xn765; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727912AbgH0WQ7 (ORCPT + 99 others); Thu, 27 Aug 2020 18:16:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbgH0WQ7 (ORCPT ); Thu, 27 Aug 2020 18:16:59 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48C2BC06121B for ; Thu, 27 Aug 2020 15:16:59 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id n3so3239079pjq.1 for ; Thu, 27 Aug 2020 15:16:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lLmbzoSbX37WRFYQW3L/1ffMVUDf88bIb2L15ySX4bI=; b=Sn1Xn765zecNGssYNGAzm6wFGVk/ZUhv3yF24YKSHrrm6U0gqIZZZDxVzDAyNtP0T4 cXAMTSit0hEdTaUdP8eWW8XSdX0PhQMN7+d7nso/G2BMTeqMHmL3Cdk9S54CZ6SMe7Zl DkBln/HezvkLX2GPBY0Q+sV4MPupwJjvZ0xzE= 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=lLmbzoSbX37WRFYQW3L/1ffMVUDf88bIb2L15ySX4bI=; b=G0EKcRLDoZkBmCrXGOyZnXnVxECdRqnoDZbZfn/q9xZdvwb3vBylRt5JGbUX0lqeCT UQ/Qh91Lt8EMm6IPaOOelCYNSs7gx9LqfvUEIRWKAvSPiy6jhsoaYDwomHQOEzsezZ85 KEHhnGnrdMboOdoKUtlDLkF7Nna54MHH6/LvaAnOg2ovyhx+3wkyICNmSUHEjifIcb6U nEZEtHlXrZjEYlOW43PLQ9SlWIAGnEdPCcXQWpMsm59dVN46vwpDAin/IBntRJPE95Fi kUMMh2UDUdTHhYVdBJT08xraJd9F7xjrVjz0EEPnBd/prgBaOg+qmnxlxIhU2i/mffTo NI0w== X-Gm-Message-State: AOAM531lw83J9eJuJ0J6eIKcWu5+iUQeNZigshaYFVStn7xv8CPISNG7 py3Js91tD1+VxFl+XA9NnhoZQw== X-Received: by 2002:a17:90a:19c2:: with SMTP id 2mr845122pjj.6.1598566618642; Thu, 27 Aug 2020 15:16:58 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id lw2sm3005169pjb.34.2020.08.27.15.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 15:16:57 -0700 (PDT) Date: Thu, 27 Aug 2020 15:16:56 -0700 From: Kees Cook To: Joe Perches Cc: David Laight , Julia Lawall , Alex Dewar , Rasmus Villemoes , cocci , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Gustavo A. R. Silva" , "accessrunner-general@lists.sourceforge.net" Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs Message-ID: <202008271516.ED209B68@keescook> References: <48f2dc90-7852-eaf1-55d7-2c85cf954688@rasmusvillemoes.dk> <20200827071537.GA168593@kroah.com> <20200827131819.7rcl2f5js3hkoqj2@lenovo-laptop> <20200827144846.yauuttjaqtxaldxg@lenovo-laptop> <5d1dfb9b031130d4d20763ec621233a19d6a88a2.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 27, 2020 at 03:11:57PM -0700, Joe Perches wrote: > On Thu, 2020-08-27 at 22:03 +0000, David Laight wrote: > > From: Joe Perches > > > Sent: 27 August 2020 21:30 > > ... > > > Perhaps what's necessary is to find any > > > appropriate .show function and change > > > any use of strcpy/sprintf within those > > > function to some other name. > > > > > > For instance: > > > > > > drivers/isdn/mISDN/core.c-static ssize_t name_show(struct device *dev, > > > drivers/isdn/mISDN/core.c- struct device_attribute *attr, char *buf) > > > drivers/isdn/mISDN/core.c-{ > > > drivers/isdn/mISDN/core.c: strcpy(buf, dev_name(dev)); > > > drivers/isdn/mISDN/core.c- return strlen(buf); > > > drivers/isdn/mISDN/core.c-} > > > drivers/isdn/mISDN/core.c-static DEVICE_ATTR_RO(name); > > > > That form ends up calculating the string length twice. > > Better would be: > > len = strlen(msg); > > memcpy(buf, msg, len); > > return len; > > or given clang's requirement for stpcpy > > return stpcpy(buf, dev_name(dev)) - buf; > > (I do not advocate for this ;) Heh. And humans aren't allowed to use stpcpy() in the kernel. :) -- Kees Cook