Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp116926lqp; Wed, 20 Mar 2024 15:49:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXe0EqyJJGxHCz5djgUalSxCVbem+6AA06+mZhuZSh9ErXsW6cEVtjT916flcTMJI5XT9qipufklbZQgTPykI8K+P5T85QeIgA0zfD0g== X-Google-Smtp-Source: AGHT+IHBc1WUFU13mR+ZPnlxIucxBDBmaXHMZwqqAcib7kxbftg3d9HqcgYQWhMWXA8mnBV98w7H X-Received: by 2002:a05:6a20:914b:b0:1a3:4638:1aa6 with SMTP id x11-20020a056a20914b00b001a346381aa6mr460814pzc.30.1710974943605; Wed, 20 Mar 2024 15:49:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710974943; cv=pass; d=google.com; s=arc-20160816; b=fVtCb8Ruq/daoviXZRgjIQp3toJ06euPVL6lQLUo0aTDiBaYZuyTS3Qe8E3CMvZ/Cw 73sw98vG8kcZSszywGH42V5BOp6KqUtzbb4J6uR981B/aNd067VY7q7pIgkbBIkKZGYo Z/HO82QOYAs6vORGuEWJ2KutLSYUpi4GaNSLx6ROIHoSUiJnVkCAWrDbfPGEM9JzMoOk 2jM6qAEE4Bnkn8AKoIQHyHD4/63hxGzDkY7AutccJ/9fFuL6PkPBT0sy49gRrP4ZGNSg hJtaXy2fbTXO23/6qi87/ngk1W9LQ+jwwUHLycjFXp8ogVz2mMlmyEfPxVIzIw9hxrYb Qx8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=cuJsz9UlwEA6zdfjk+8N140o8FRIcxJ5QLG1a0ozWdY=; fh=eJ5ULaRnOBdC0aRxbkBX3V23io3kRmvR7asaULGo/NE=; b=QJfG3SiHtZsrNTBTNuOOIB/MVPv/ke5LghioN8NNbvAD2NJ1LdHuS9+P35dvHyBBTI L12gFRLzkO9lQd03XH3Ftd0S6isOVp98fHjtMwnZVqAvJ9QiPCjhcBp948ASUGP1kO4z 6jXgyI6aS+h10yXCm69oTXS0RL4oSeKOe8LDGhg1ZkOuf7w6BeKJA/brYQYYKN2roHvw /njZtiCWZra0JYpT+YvxsONEQC0mrGqX5uL37v/4rwfgdCboWKV8fIxzrzxzim7agiFb tR/FfNT5vvoJxbceWAKEnHXNX8+51h/GBdsRlwSwK6Syjob9pB4brFmpQjNrq/2byF6F 0dag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WHUUy3ZP; arc=pass (i=1 spf=pass spfdomain=flex--justinstitt.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-109471-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h4-20020aa786c4000000b006e6b0e99fb6si13761634pfo.8.2024.03.20.15.49.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 15:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109471-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WHUUy3ZP; arc=pass (i=1 spf=pass spfdomain=flex--justinstitt.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-109471-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109471-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4AD2D283FAA for ; Wed, 20 Mar 2024 22:49:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B64B85C59; Wed, 20 Mar 2024 22:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WHUUy3ZP" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 BCAFA3FBBC for ; Wed, 20 Mar 2024 22:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710974936; cv=none; b=QuelhVlQeyFRQeS/hT+K8aYclf4R6XqXl2QlK7uFMhFehmo096nK35Eom9yhx89Doj4iAc7DjaO45LbvUVoW71tm9qKf/3+JrFpc1uXEWVQokdsURYn2r3ehSZCxTPMJKNRyJ5ImHGHjnXjzg4WQMLH+cCK5opiqk3DieSxn3rQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710974936; c=relaxed/simple; bh=V7XSTOhNvjEuLafgGT0fgGD4qu2T4mLPqEmu44WjLQA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=uej8a7FGMKo6u6YDU6IQ4AaUileg7B9jBqzDQKUjpvoDPFLmocM1zUiP8ho1T8rVqEBWxSablpCG6CIlpJwR1vjsv86dK0suhGFSzxI/yiQ5uIC/gHJgemMf6gWWQJaXy0favRCSztPi79wXynqNI7kdFzDz0Blb46bi/ktu7q8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WHUUy3ZP; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a0815e3f9so4567707b3.2 for ; Wed, 20 Mar 2024 15:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710974933; x=1711579733; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=cuJsz9UlwEA6zdfjk+8N140o8FRIcxJ5QLG1a0ozWdY=; b=WHUUy3ZPEKlcPGbCtgfMhAV3BUXSEsHrJPuiSMZ2VCOJzLGZ7RSo1AtgfZkZiJxMf7 6zicp3IdB8tX0jnvQXW5fIZZUZKyf90FTzrXfARVAM4AJep1R4+W2BpH/nRziDzW9tSQ 1xcpi75Q+PuSkD8E31Cstb5UcOE7hPvYEXyvb5G7iMJ9VaxTOz3pdg9DMCm6Ueo6upuq zuzxXbb/Oltd3gsonrm/t5/xZekyratvSNbDbDxTx+hH14MVAspNvnXMTZKyuvnLx+lF zJc8Bpt2aFSBnC1SvBQs+lE8bzRJC1BBDQwhBBJkVHb5HikR8qY40OJOL8IKBjwYYEFN cLVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710974933; x=1711579733; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cuJsz9UlwEA6zdfjk+8N140o8FRIcxJ5QLG1a0ozWdY=; b=nbEPrGJlr5XMwAYuN23xDoZ4mEl6Vjd/Ss/ocLcAD4W2H7ZCm3Z1F/Kx2YAwsxgNxC E1YjpAt0j0OJ6DxfokyCXZzYIeuV2THXIlnKZdFgODXHlNTMM6cVU56LMMpBvt79r+2L 4Ozg4vJg+bQkzQE1/r1ltp+R+YfM9tu0WXrmI4Ue0UWlkw3j/R0TgUmL0Vv2u8Ep54Cf 6a8ZH5G7g0cih4KRTzas3bFV6YxmDRQeUAIhchmw+NJqPtEo3fuA+EsTiQ3kUnR53f3t YDjVOHmHBu50c5EfqYq2wNh7eSHLxN17yNsW546AmQJmTK11IL4Uf9D0ayt3Ps9tDdvX GSSA== X-Forwarded-Encrypted: i=1; AJvYcCUkaaWd5gijz4hXaKmUGazKhEh3/pk441+jGdztlEu/ePxzs6hNBtmrbKb37NsAYgMR1N+v+2f/h15yjQ5CT3Fi+i2IqhrQd3F+6THI X-Gm-Message-State: AOJu0Yy/MSiH952Ry7jYvHnH2pehHK5dgkSeKNHyEI51kcmfkNFrHfxP 1m2B2j22RpU4aAOUBoExQVpkqRE6V7J4cDBTmvf2zMMQlJRA11RHsi/MRHFOwh5t2AFbvsX72H1 m/x7J7qGSjZrOYBx5dma/3w== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a81:91d7:0:b0:60d:6e32:2f70 with SMTP id i206-20020a8191d7000000b0060d6e322f70mr3604527ywg.0.1710974932857; Wed, 20 Mar 2024 15:48:52 -0700 (PDT) Date: Wed, 20 Mar 2024 22:48:50 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIANJn+2UC/x3NwQqDMAyA4VeRnBeoVgT3KuJhbVINjCqJlg3x3 Vd2/C7/f4GxChs8mwuUi5hsuaJ9NBDXV14Yhaqhc13vfDuiHZrj/kVSKayGRYg3TIG4YLI3kpx VGDEMo/ND5OBTDzW3Kyf5/FfTfN8/1lDuSHoAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1710974932; l=1938; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=V7XSTOhNvjEuLafgGT0fgGD4qu2T4mLPqEmu44WjLQA=; b=igy7d94UFbUM0TkUAgMVJDxriGbnH+DPKvEXXYKfS+CKktomyiqlyOLzVVQxq4ZffMDfFel3O h2XGTp+4Dh/Asd4C5wNyBMFsacdao+pZNwmAm8/6HIhl+l027RuOSV+ X-Mailer: b4 0.12.3 Message-ID: <20240320-strncpy-drivers-video-fbdev-fsl-diu-fb-c-v1-1-3cd3c012fa8c@google.com> Subject: [PATCH] video: fbdev: fsl-diu-fb: replace deprecated strncpy with strscpy_pad From: Justin Stitt To: Timur Tabi , Helge Deller Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. A better alternative is strscpy() as it guarantees NUL-termination on the destination buffer. Since we are eventually copying over to userspace, let's ensure we NUL-pad the destination buffer by using the pad variant of strscpy. - core/fb_chrdev.c: 234 | err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id)); Furthermore, we can use the new 2-argument variants of strscpy() and strscpy_pad() introduced by Commit e6584c3964f2f ("string: Allow 2-argument strscpy()") to simplify the syntax even more. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/video/fbdev/fsl-diu-fb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/fbdev/fsl-diu-fb.c b/drivers/video/fbdev/fsl-diu-fb.c index 0191141657fd..ea37a60da10c 100644 --- a/drivers/video/fbdev/fsl-diu-fb.c +++ b/drivers/video/fbdev/fsl-diu-fb.c @@ -787,7 +787,7 @@ static void set_fix(struct fb_info *info) struct fb_var_screeninfo *var = &info->var; struct mfb_info *mfbi = info->par; - strncpy(fix->id, mfbi->id, sizeof(fix->id)); + strscpy_pad(fix->id, mfbi->id); fix->line_length = var->xres_virtual * var->bits_per_pixel / 8; fix->type = FB_TYPE_PACKED_PIXELS; fix->accel = FB_ACCEL_NONE; --- base-commit: bf3a69c6861ff4dc7892d895c87074af7bc1c400 change-id: 20240319-strncpy-drivers-video-fbdev-fsl-diu-fb-c-b69036ceb3f4 Best regards, -- Justin Stitt