Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1589146lqa; Mon, 29 Apr 2024 12:49:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVas+h0Mdtry2tsyAUElV22LKCe9+dnAzmpL9FxZOCLTlOCpqE550ajgJiZvghmvUNEzryHVrq5juOn+vm6dfaxvfuKWJDCkoM10m0zJQ== X-Google-Smtp-Source: AGHT+IF+oDsOeP7CBzaT+VzUXMOdMFqGzg1Zx6hvSlcdfSMWqwtsubjleYT6qIDZMzK4htnRqktf X-Received: by 2002:a05:620a:2904:b0:790:e848:d435 with SMTP id m4-20020a05620a290400b00790e848d435mr7986378qkp.0.1714420198891; Mon, 29 Apr 2024 12:49:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714420198; cv=pass; d=google.com; s=arc-20160816; b=gnVV4ha4yz5b+tHu+z+MEYEUc2d5lYTypT1QbE58yPcxT4tgL98hcdbzh+FwmJJCh5 L8OPYNL0QaUuMGqberessWxWfDa1ZF0wd0j0iRtZ4vRUJP4gIjf0zz232lVBt9QO6HbU SGFUPLeVoAGThrt9mzd2+9VzGG5ekixP/gn+3kcnxZij2pRPwUFHcJ4hwAWB/AV0mJU0 Q0CGZ9Vxf1Bc8HpsHfnt3jsUaLu9tR+H4o2ZFtG953nDmhGMeOQVLbTr/7zGO0EkQwZV DyX0wCQLNYqS6cP2HO6Q2uQLDoLHXDivfgakT2yJj/lLVNAcgMOiSjJRT4tuBt+iodkY medQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HdmEYuDR/RJEQB35GPv4tDo/+p4YFOvYsLxCcDQQsi4=; fh=4d/aEOeSjS+Hk/G1ZBY8eiHGHiMKNaks0R7eUGGmxnU=; b=WO7zSklMjOI7TPJkfB1dhWesKhY+z/3y2ZzEUDZWQFnuGu+T5EW8Q2zd4c+fWJoWGZ 27FNGBwlNEQ/tq1W5+0ayyeNkhC5HH8fyulzrqM5kdEnp82z2eIHgDVgsvGJ3y6b4dXT HzJBgazP5XOZdf+0DDvKUkD9RmZw2i6Uj+B4lPRiF4OEEewdvhqB5bx2jn69YsmCGKgE JigDGNeBoBt77/PEv7wZEcCfMtvFYLqGTM4BPFBDeyV6Hm9Nmo20kBemIBglWMfKX6nz btNhoJ/v1gQ+3Vf+zEvGecCWiMRTXgzzcchg0k6kGbP96jMujZxjKkpvW75T1HnXOZAG DrJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hFBGjjrm; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-162969-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162969-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id eb3-20020a05620a480300b00790ec573ccbsi5022764qkb.226.2024.04.29.12.49.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:49:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162969-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hFBGjjrm; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-162969-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162969-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9E1551C21A1D for ; Mon, 29 Apr 2024 19:49:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D1B513D618; Mon, 29 Apr 2024 19:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hFBGjjrm" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42A2D13D600 for ; Mon, 29 Apr 2024 19:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714420191; cv=none; b=qBGdn+IoMpIsMlcCzFou8NjnXykj1CIh0BVnpqnYhw4vp0QTDsej+0XYN1FknZQi3Qod7suTNL6oaT3ziM6x2FjP0v4hACI9qdryJCSzcp7yiE2uhH6RFgEKUs4h4SMgfE1zyEtnP3Qezrm2aw/rTLXRPATdrPTiwThKyKIVwAg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714420191; c=relaxed/simple; bh=fLy9wuUj7qj/KLGKoiK5/omRxQbXTc/lSN/3AugUd4g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ETch7SN8Y8vfo3g4zy4lpVMbxJYOg4FsOy6sdPtc0OGYYyLG+wDaNE1lbQJxNKkuUbOgJhREcUUIY1iNM7CT2LXJw/rHIu8s+eFt0yG2SMyEfplPCF72ydQutjcyB5JLplIkNNdV4vT+Q10ydNjKcKw9XgbButLnSrWUao59oyw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=hFBGjjrm; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6f3f6aa1437so1646490b3a.3 for ; Mon, 29 Apr 2024 12:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714420189; x=1715024989; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HdmEYuDR/RJEQB35GPv4tDo/+p4YFOvYsLxCcDQQsi4=; b=hFBGjjrmupEELOGBImuHMuFkbG6kgsEK4o9GXNq7ILpZ4p6QC3OhT9FOjIhH3+muUE RlX5i60LxP0MZuHjW28H2rDZ+d70mD6jbBtAxMwbyI6EFOVz0FiXpeD8MG9cJ5nEwVtj qavG754xc3mvGTYUJe2eVq6lSM1H7QAio1xPQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714420189; x=1715024989; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HdmEYuDR/RJEQB35GPv4tDo/+p4YFOvYsLxCcDQQsi4=; b=EbmIYrL+YnqAk1cEdf6rhEpAatPucfLVNYj6XHpdushJSDbRRKImPKUOPbII9ov6on AA2KrD1IN5HEOfKUskde+ug7CrXVIEWHsEw+2SsQxbF+1s1vGYNU17pJugrPwplgbgvC LFADT6wfH4B68gF11Eh8Wj/8NRqfvamVJllsfn9H5jZPPI5NPod1yWxdTNuGXSRurq2P qEN8lX37cpCGqiZVOXhn0xcY9AFpKGI26jaEdhLSj/43IZeCF/IosCEjPZsMgO0qqBVZ TAv53bMirv9z5fI616WKJvqoa1o4Vwjdrm+Y3tDPIWvs2bzIet6vcu8Z5umDYduAWWY2 REYA== X-Forwarded-Encrypted: i=1; AJvYcCUatfMV8tgM/CSE6yCX8q/1rZktKfBtTFVO050MXT75sKPHg7Hxvc6KJH4KFE3/7zHTIUIPf1s5AZMR2J98KwKsobdnkbzgzpCETVTm X-Gm-Message-State: AOJu0Yz/JV2JhhpJWHxoUj6AytYTOU7taFC764GDVIKfLAlgfmbbYyp+ tfI3bz65+Pfn5WXVz00XH/1pEsmr+Yr5DBRzzwTIUSoa0fZ9gqmV5wjTb2qD5Q== X-Received: by 2002:a05:6a20:9f8b:b0:1a7:7358:f108 with SMTP id mm11-20020a056a209f8b00b001a77358f108mr14742494pzb.24.1714420189565; Mon, 29 Apr 2024 12:49:49 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id q5-20020a170902a3c500b001e8532292a6sm21156271plb.195.2024.04.29.12.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 12:49:49 -0700 (PDT) Date: Mon, 29 Apr 2024 12:49:48 -0700 From: Kees Cook To: Justin Stitt Cc: Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , linux-kernel@vger.kernel.org, Lee Jones , linux-hardening@vger.kernel.org, Finn Thain Subject: Re: [PATCH v6] checkpatch: add check for snprintf to scnprintf Message-ID: <202404291249.078D924@keescook> References: <20240429-snprintf-checkpatch-v6-1-354c62c88290@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240429-snprintf-checkpatch-v6-1-354c62c88290@google.com> On Mon, Apr 29, 2024 at 06:39:28PM +0000, Justin Stitt wrote: > I am going to quote Lee Jones who has been doing some snprintf -> > scnprintf refactorings: > > "There is a general misunderstanding amongst engineers that > {v}snprintf() returns the length of the data *actually* encoded into the > destination array. However, as per the C99 standard {v}snprintf() > really returns the length of the data that *would have been* written if > there were enough space for it. This misunderstanding has led to > buffer-overruns in the past. It's generally considered safer to use the > {v}scnprintf() variants in their place (or even sprintf() in simple > cases). So let's do that." > > To help prevent new instances of snprintf() from popping up, let's add a > check to checkpatch.pl. > > Suggested-by: Finn Thain > Signed-off-by: Justin Stitt Thanks! Reviewed-by: Kees Cook -- Kees Cook