Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1017439pxa; Fri, 28 Aug 2020 01:00:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8V7T8F1/iTZCjn3Tq1QHWNg/31zeFt/bAXa/WMF6AqwtcSsEZcyaFOVz6vGy4+/rZojmG X-Received: by 2002:a05:6402:1299:: with SMTP id w25mr587430edv.349.1598601608228; Fri, 28 Aug 2020 01:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598601608; cv=none; d=google.com; s=arc-20160816; b=GCpNmKzpFCI0P1I6l4BL3h/qGxlyU8vgs6CyqIeDmnS6CCy4WIolfWCm/PLDHTyvEz xfle3B4TN64D/qxqai7iltAaTeaJEb6CN7tgnKZv+vaGskcO8NxMsicBQNyHeA2uYWwz V8BgdCXzrtltYfhleQLvjXtnDDZVqTZmJLkDX9Ecq2bMWd/ymaBmlUvXS+iniUvmtsfP zd1VC7U7qDNKnOQPyoG7SitEHfktEZdmoIHoUuHMjqedpxGF+Np0iuhDuiSenCJPBsqe 7PLFgwxtlyXVHgznMAc8YNH+6cHs0BSbzVECnqQmWB6Ch0Lq9jQIwMZGYYj0+PRSCgs2 f4Zw== 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=PElpbzIDHomzRDBqhzC9EtSuGk5dGo9/mZ4Zosmva34=; b=UvgQUTS6uaw9fv89Mgr+PUA1/EsHMtWZvchkc1yKv/epPhFoRC0JwsquGmec4pDW6a 2AXuoAB/2FIkpudSV7OHHVDmX5W7mMyMMIXuYVn9KQ+5ONln15SSLbVfe6aedTSzjkeY 2A57oTGKNgP8mwhhbf6/2NPSEv7ceZ1B3MRqNzLIcCu+YbvfHVN9gGfJAOZwqUwiP2wK f6mTbzlxGhLUisdyEDI9lSZTvCsgoWLkQiA2Sd+05plIneazdjLPDRPRnIde3EnpAOFU xYPacc0b5zab1J7BImR0DjJ5kDREJnjDzbpzJZF8hQ/W6zWyAuyf57oUc4b/rI6SyclK y0yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ISB7ntnk; 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 s5si130100ejz.589.2020.08.28.00.59.36; Fri, 28 Aug 2020 01:00:08 -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=ISB7ntnk; 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 S1727971AbgH1H6l (ORCPT + 99 others); Fri, 28 Aug 2020 03:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728218AbgH1H6k (ORCPT ); Fri, 28 Aug 2020 03:58:40 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1D1DC06121B for ; Fri, 28 Aug 2020 00:58:39 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id i13so169113pjv.0 for ; Fri, 28 Aug 2020 00:58:39 -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=PElpbzIDHomzRDBqhzC9EtSuGk5dGo9/mZ4Zosmva34=; b=ISB7ntnkpAQLBD08Qe+CwRG4oyGX7bNu/54ttG6U4kcZTr1CXqDq7aE+vYsiYrQ3XC fhJu3Ot9XdAp4t9UCHO6tiaW9UlBnbYqGlXJetJ0SNrvmGpkR7KXkZ2OP4/ljZQVwmRF XYYJOVWz5g8XjNxGsph+V5EoqidDtb5wUP1nY= 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=PElpbzIDHomzRDBqhzC9EtSuGk5dGo9/mZ4Zosmva34=; b=qaUk9ZwdC1YwDgFLQlT9fsmktmGJcPCBkil37O9gXlUMaHEArHEnUvIlXL7LKChQn7 1eiuBiFTayufa+Gz9UuOPP1Pg74OCTzjzZC6Gg6+6gM5fDHiqDXRmORwLLKIfzvaeo+G Sybv9zY2aC/WrpOh/Ke23S8i+kHxnGMx7EXaRQkmkW4K2JPzTl8Z1vdq8Bp0pS2bXirz 9fCsJoUV4swG/LjH3QI3dsmsbASeX43M/94YAdJVj33ZKjm07naLNNzptbkroYecvQEB fhqH/VW7c2ZaXG60LdxI96RpchRyD3MTPMlWl/gFAnGMuESK02vc+UJBvakFOCu9osCd jx4w== X-Gm-Message-State: AOAM530orXOjfWtZzbSjsI1iu+bsaf64akVqAwk5R8qowgcf0ekGrhKf pk0O/KiDiuI3LCIdb6Pzwng7Wg== X-Received: by 2002:a17:90a:b10a:: with SMTP id z10mr223586pjq.102.1598601519328; Fri, 28 Aug 2020 00:58:39 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y7sm403384pjn.54.2020.08.28.00.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 00:58:38 -0700 (PDT) Date: Fri, 28 Aug 2020 00:58:37 -0700 From: Kees Cook To: Joe Perches Cc: Denis Efremov , Julia Lawall , "Gustavo A. R. Silva" , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Rasmus Villemoes , linux-kernel@vger.kernel.org, cocci , Alex Dewar Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs Message-ID: <202008280056.6442BCC@keescook> References: <20200827071537.GA168593@kroah.com> <20200827131819.7rcl2f5js3hkoqj2@lenovo-laptop> <20200827144846.yauuttjaqtxaldxg@lenovo-laptop> <5d1dfb9b031130d4d20763ec621233a19d6a88a2.camel@perches.com> <5853c58e-7d26-2cf9-6cbf-698ecd93cbf9@linux.com> <202008271517.ECC1F1F8F@keescook> <5ebe5c2737b59d04f1b8a46008cd3159c638f9d0.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 09:12:06PM -0700, Joe Perches wrote: > Perhaps something like the below with a sample conversion > that uses single and multiple sysfs_emit uses. On quick review, I like it. :) > [...] > +int sysfs_emit(char *buf, char *pos, const char *fmt, ...) > +{ > + int len; > + va_list args; > + > + WARN(pos < buf, "pos < buf\n"); > + WARN(pos - buf >= PAGE_SIZE, "pos >= PAGE_SIZE (%tu > %lu)\n", > + pos - buf, PAGE_SIZE); > + if (pos < buf || pos - buf >= PAGE_SIZE) > + return 0; This can be: if (WARN(pos < buf, "pos < buf\n") || WARN(pos - buf >= PAGE_SIZE, "pos >= PAGE_SIZE (%tu > %lu)\n", pos - buf, PAGE_SIZE)) return 0; -- Kees Cook