Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp822885rdb; Fri, 1 Sep 2023 05:27:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGsQaxVnjNVxoTvDbOtXNmUS1TKoAjwnPFf/nU6aZoVddljQ2Uao3dn7PBe++ICL8Suyce X-Received: by 2002:a05:6e02:d0f:b0:34c:e2c5:bf6c with SMTP id g15-20020a056e020d0f00b0034ce2c5bf6cmr2277194ilj.28.1693571238411; Fri, 01 Sep 2023 05:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693571238; cv=none; d=google.com; s=arc-20160816; b=t4e+LvFdojs7gW9aXcABK4lNlpuffLcxaySy+tyJ2OfDScpuvJevXp5Z8CHjGyWE2U +D3qYj1B800DqTBZcP3/sD2lba6vyDk2nT34zNSeDLMucp2RPnFI5DZm/1+RcuGlbqkw d++/CwNMHH6HNokjCyoa9eb4ymulq0IKKH1Af25lsSnvU4XJqYsImKtISW8OfIJmJ3wl 6lkWSgZOwi0/6eGut/N0b87X90yEDeVH8AAm66NWojGmVOrGMSU8P0XKazaGhZRyWJ6x AEjsGiMAPlc5EgajvRBl3hmyN7N1y500MtPF0PtK9vbLu2wv8JJNV2DKjb5BswJQ7TgK 7egA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=4NuotZNWURxGLA5Vp9fFE3VQcy9WCNwbfbI0Vi4Osao=; fh=wEm5CrUs6P0Q7ELhGgkR+U4dHN4Jf2HVnPMMVwYutNI=; b=PpgMhLnfJ88mkvjO+G0sXRIKeobAJBQYaSe1sVmNQdI01VtIGBIZf/aLldDo85IgmC +LfvV+LYRhMPOPcMBBF2h1HqK/nkC2potRfAp3ZmyeiWyWPtXgYue2/WorHwJp5j0mqC uRfvnrc06P1JflxVG/2reFF+6DFRWgBh2B/2HkskgNNHoO/F5XFz6MSpv8TsTr+8MeXG r52LaX7qKsz+URGiNYSwEmxqil3H3dxTQKPBVGpVtFYzN9zunDSpE/lSSs81kJr2qRlL nXJHpjAmVCtXLzTdblLQUnDygRHt0FnpIoPrPEGvyCgHXDOLVbYTjnXn4jTP+NeuzGgG IQNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h36-20020a632124000000b0056950006fd5si2904242pgh.885.2023.09.01.05.27.04; Fri, 01 Sep 2023 05:27:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347620AbjHaWQK (ORCPT + 99 others); Thu, 31 Aug 2023 18:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjHaWQJ (ORCPT ); Thu, 31 Aug 2023 18:16:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81ED2C0; Thu, 31 Aug 2023 15:16:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1942FB82428; Thu, 31 Aug 2023 22:16:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65A00C433C7; Thu, 31 Aug 2023 22:15:57 +0000 (UTC) Date: Fri, 1 Sep 2023 00:15:54 +0200 From: Helge Deller To: Nick Desaulniers Cc: linux-fbdev@vger.kernel.org, dri-devel , clang-built-linux , LKML , Andrew Morton , Nathan Chancellor , Kees Cook , Justin Stitt Subject: Re: truncation in drivers/video/fbdev/neofb.c Message-ID: References: <9d2bb495-0c1d-0d1b-96ea-4b1110d45b79@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Nick Desaulniers : > On Thu, Aug 31, 2023 at 2:23 PM Helge Deller wrote: > > > > * Helge Deller : > > > On 8/29/23 18:45, Nick Desaulniers wrote: > > > > A recent change in clang made it better about spotting snprintf that > > > > will result in truncation. Nathan reported the following instances: > > > > > > > > drivers/video/fbdev/neofb.c:1959:3: warning: 'snprintf' will always be > > > > truncated; specified size is 16, but format string expands to at least > > > > 17 [-Wfortify-source] > > > > FYI, I've added the patch below to the fbdev for-next git tree. > > [...] > > This indeed makes the warning go away, but that's more so due to the > use of strscpy now rather than snprintf. That alone is a good change > but we still have definite truncation. See below: > [...] Nick, thanks for your review and findings! Now every string should be max. 15 chars (which fits with the trailing NUL into the char[16] array). Helge Subject: [PATCH] fbdev: neofb: Shorten Neomagic product name in info struct Avoid those compiler warnings: neofb.c:1959:3: warning: 'snprintf' will always be truncated; specified size is 16, but format string expands to at least 17 [-Wfortify-source] Signed-off-by: Helge Deller Reported-by: Nathan Chancellor Reported-by: Nick Desaulniers Link: https://lore.kernel.org/all/CAKwvOdn0xoVWjQ6ufM_rojtKb0f1i1hW-J_xYGfKDNFdHwaeHQ@mail.gmail.com/ Link: https://github.com/ClangBuiltLinux/linux/issues/1923 diff --git a/drivers/video/fbdev/neofb.c b/drivers/video/fbdev/neofb.c index d2f622b4c372..b58b11015c0c 100644 --- a/drivers/video/fbdev/neofb.c +++ b/drivers/video/fbdev/neofb.c @@ -1948,49 +1948,40 @@ static struct fb_info *neo_alloc_fb_info(struct pci_dev *dev, switch (info->fix.accel) { case FB_ACCEL_NEOMAGIC_NM2070: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 128"); + strscpy(info->fix.id, "MagicGraph128", sizeof(info->fix.id)); break; case FB_ACCEL_NEOMAGIC_NM2090: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 128V"); + strscpy(info->fix.id, "MagicGraph128V", sizeof(info->fix.id)); break; case FB_ACCEL_NEOMAGIC_NM2093: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 128ZV"); + strscpy(info->fix.id, "MagicGraph128ZV", sizeof(info->fix.id)); break; case FB_ACCEL_NEOMAGIC_NM2097: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 128ZV+"); + strscpy(info->fix.id, "Mag.Graph128ZV+", sizeof(info->fix.id)); break; case FB_ACCEL_NEOMAGIC_NM2160: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 128XD"); + strscpy(info->fix.id, "MagicGraph128XD", sizeof(info->fix.id)); break; case FB_ACCEL_NEOMAGIC_NM2200: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 256AV"); + strscpy(info->fix.id, "MagicGraph256AV", sizeof(info->fix.id)); info->flags |= FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT; break; case FB_ACCEL_NEOMAGIC_NM2230: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 256AV+"); + strscpy(info->fix.id, "Mag.Graph256AV+", sizeof(info->fix.id)); info->flags |= FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT; break; case FB_ACCEL_NEOMAGIC_NM2360: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 256ZX"); + strscpy(info->fix.id, "MagicGraph256ZX", sizeof(info->fix.id)); info->flags |= FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT; break; case FB_ACCEL_NEOMAGIC_NM2380: - snprintf(info->fix.id, sizeof(info->fix.id), - "MagicGraph 256XL+"); + strscpy(info->fix.id, "Mag.Graph256XL+", sizeof(info->fix.id)); info->flags |= FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT;