Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp132272lqp; Wed, 20 Mar 2024 16:27:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWFzXrNCGc6C1/BobqHqbMpeqfkiHGeT208LGAfE+c3K1bXfIP3ZB07diL2r8cYIxs6DzivbqPGJ0PdiZdsdj0bs0fUKAMMa0b9w+pPaA== X-Google-Smtp-Source: AGHT+IGrfODztgAf+zScrT6Nb6I0pz7uyAY6cYeSAbbs15UoghNDlhclmpMzz4F/GPOjwi79eAkd X-Received: by 2002:a17:906:aacb:b0:a46:2a47:6f4c with SMTP id kt11-20020a170906aacb00b00a462a476f4cmr2120287ejb.60.1710977240513; Wed, 20 Mar 2024 16:27:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710977240; cv=pass; d=google.com; s=arc-20160816; b=A4K0lt5amg8DFXOnjJCP4Mb5EuotzGUTdUPEuYzrfNTWWnUm+agrh/POeTdzBr9M7m wIUtXU24wTJZmn2rkm2uD8swbq7H1v3bVaO13ytmrM/2DcokIVDUuLfSOba006ZiuE7a XRhGxlnVuZzXiHk2QGjJktkbRUvWzNRdwTggk05+IMxT0vIY9Dk87f6hY7Yo+VM3S+mx jdlozTltVdgAZizUTBAj0MBnNeHfD7Xu70WtkaXCDOVS8X/UA3EvTcb50Fm9F23s973D lbMjWmgK8jKfsVjKumoNMh18lWfLItMf4I1jKk5BaET06Tc5C/dWzwPq1KMNqQNXkj3w QGyQ== 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=AKP8GbnuNaUxisIiiCc/HvCd/U76hXx8XgrXiVPpGRg=; fh=vsA4TgtswN1HBcHDDwt55UvTq2oE8f5hQzqWkNQGW7o=; b=JLIB+nIGB+tbpEG37naC4Iu7SmKRVPmHfxO1Gbcb+6IZSD79nYzyJz3YD5q8t88nvP t7BHQb6QCSKHkg2rA/P1VFtlQdcm6h6QDNX/m2SJhDgIQGTAsjtwKKTfmDG8DKWIgAjf R3Itr0879zEgRLYhXI3jSwY0PWAbGhJNotnbF6arENZbfNms1tROdOGtMFhS7lS2jfGd Kd+ZD72nHZPwgFGZ14FmtlX0Vn3dr5geq5FimeB+2qL/heJIFLGkogkXh5YEFj2MCUov 4uOMbxkmlR/9WLBVhS1FygLE1fMSzHz53F6PDs34YgyWrHJvMGkYywQeGP3cT87+aJQm Fw2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mbOu97p1; 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-109488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cr21-20020a170906d55500b00a46e12d208fsi2052192ejc.808.2024.03.20.16.27.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 16:27:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mbOu97p1; 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-109488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109488-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 126801F21DA9 for ; Wed, 20 Mar 2024 23:27:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02E8386146; Wed, 20 Mar 2024 23:27:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mbOu97p1" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 AE81385C7B for ; Wed, 20 Mar 2024 23:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710977232; cv=none; b=nMl7nUm/B361SDdz+csPtOKPx+lN1Ng5VCl/VJYVxmAPGXafTCtf4OGCOfvPSi6XXMbmQFthmC0wv3Yh1B8HCjM4Hqe0X0yZnKIQVzKGWhI/MxklQZw33VPpbJwUQFn13DVK+XoWhvrwgx3YsbsescBSCRgj2d7AMz9d+y7qDWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710977232; c=relaxed/simple; bh=vYKzzse+hsxrCLrxZ00MkHClgVeFa8yh0cRD/lbNsc0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=OTAEe14SyK5k4qBfs5PwzueP51KEVl/O52y3YYawltdfEf6lX+MzETjBL6kO2D7HRVKSurkFUR91SQ1sx2aGb/Qt8tQ/pzZqWwCWAQVCdD3pUy3f8HaZqqKfAs12S1Q9aPUiy3oRlGiJKBcWBViRkPrQNbxE+bPGVTgVZa8Q2u0= 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=mbOu97p1; arc=none smtp.client-ip=209.85.219.202 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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc74ac7d015so462957276.0 for ; Wed, 20 Mar 2024 16:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710977230; x=1711582030; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=AKP8GbnuNaUxisIiiCc/HvCd/U76hXx8XgrXiVPpGRg=; b=mbOu97p1p0S1VxmokEH49hJg04X4G+yTVss3asgF3kK00Lgs++BSGfWPBfLv4dI/LV zuNOJJyRCBjZa5bWAqepwFZdKx4zCLUraCx8Vl1Bvlu6u7M8voEv8pR1xnkGCF8dMOLU xWk5oSJHGOzaKqm9ud+vqAgNuqImPjXtJ9bjyVeElFeyGAsptkQe/EWUc5NOlhGJTr7O E5MusuGm9EaBtmYWUJAMFj86iO4PDgUnzaFCGt3EAUKsbBFjQ5sCnRvPpg2A8dL1P5pq NVXvBccnZyusXkJMMm4HqQiPSF+2eQoaEaaG2PDDw6LZ20RvC6e71QXGql9yBrIpI8Iv Bphg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710977230; x=1711582030; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AKP8GbnuNaUxisIiiCc/HvCd/U76hXx8XgrXiVPpGRg=; b=Z/oWnQogsyTmJ7XfdIgdn93R3Ehws4pPXquh40MV0jG1V7LCFW8dYbO3DMZ6dYtuLH x89o7dIyHL3HYi21Cazm2Mbd9mGCMFxNefon59pZWRTL68a9ThoryB5ndLlP8/DboBIr NmFkMEZS40A1a3ZrUmB2a22vWxOyYAF0Ef6gZj5LQCWoN4y5SkKu7+CC+0CgW6b6MCVR zRnm6EOcjnHyMnWRsBcgVd4vmakOKodkMv5q3Am2SZhok+SPVTUCFgq2hnv8yLY4VKDD PRJlcJ7iYfyHdaDeAhf/XRASQ8q1uWsEnFVK+tFDzroq9UPyEtUtn2CcMw2WKE2VRXwA BcmA== X-Gm-Message-State: AOJu0YyyWxnUA4xqhnIgj5rgBPRGByQl4YM8TA/YMUC+0QaM5KLi/GF7 HrC30MgWuTyt//aB7YkjzcHxvI/dwYk1VPf6r8ZZas+npS0an8QVa7yNmQD+UdLxiRxVoW6x+gE uSyDrw6eYjRa209pWmhg+rw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:2305:b0:dc6:b768:2994 with SMTP id do5-20020a056902230500b00dc6b7682994mr918835ybb.0.1710977229829; Wed, 20 Mar 2024 16:27:09 -0700 (PDT) Date: Wed, 20 Mar 2024 23:27:09 +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=H4sIAMxw+2UC/x3NQQ6CQAxG4auQrm0yDGCCVzEuxlK0mwH/kgmGc HcnLr/Newe5wtTp1hwELea25Ir20pC8U34p21RNMcQ+dDGwb8iyfnmCFYVzMWycBJltgX5YeBz bLg1y1ficqXZW6Gz7/3F/nOcPhdn3TnMAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1710977229; l=2043; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=vYKzzse+hsxrCLrxZ00MkHClgVeFa8yh0cRD/lbNsc0=; b=JC/x3li3W2pIluLdOmvQqlnTTHJNWulUTgz/kp1a57t3nVdHtwUTqdlFRVQV3tPE7LOa++mOB w6h6FYYjPdHD9R8HrU1SqQwcvixMX5Pj/cSMx/32f0OMzmjUZDgR8Jf X-Mailer: b4 0.12.3 Message-ID: <20240320-strncpy-drivers-virt-acrn-ioreq-c-v1-1-db6996770341@google.com> Subject: [PATCH] virt: acrn: replace deprecated strncpy with strscpy From: Justin Stitt To: Fei Li Cc: 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. We can see that client->name should be NUL-terminated based on its usage with a %s C-string format specifier. | client->thread = kthread_run(ioreq_task, client, "VM%u-%s", | client->vm->vmid, client->name); NUL-padding is not required as client is already zero-allocated: | client = kzalloc(sizeof(*client), GFP_KERNEL); Considering the above, a suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. Note that this patch relies on the _new_ 2-argument version of strscpy() introduced in Commit e6584c3964f2f ("string: Allow 2-argument strscpy()"). 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/virt/acrn/ioreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/virt/acrn/ioreq.c b/drivers/virt/acrn/ioreq.c index 29e1ef1915fd..e94358239a4b 100644 --- a/drivers/virt/acrn/ioreq.c +++ b/drivers/virt/acrn/ioreq.c @@ -433,7 +433,7 @@ struct acrn_ioreq_client *acrn_ioreq_client_create(struct acrn_vm *vm, client->priv = priv; client->is_default = is_default; if (name) - strncpy(client->name, name, sizeof(client->name) - 1); + strscpy(client->name, name); rwlock_init(&client->range_lock); INIT_LIST_HEAD(&client->range_list); init_waitqueue_head(&client->wq); --- base-commit: a4145ce1e7bc247fd6f2846e8699473448717b37 change-id: 20240320-strncpy-drivers-virt-acrn-ioreq-c-9913a5c6e2bf Best regards, -- Justin Stitt