Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp530210lqt; Mon, 18 Mar 2024 15:36:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBedwj7BVTPyRukyCsr5aItqwULMQXdejM5dAifFFGQ0OXVNSc+LpCa1nte6jDb0Rh8HuFAdZU/2iWxQQeOtqLcDL/4N3VcNNzBpTaZw== X-Google-Smtp-Source: AGHT+IEGEApp8GcUlbnRpdOKA0iP/IpHONsG8gRixCltLtUgX/EORhLrgdhlea6Vc4vqNLVk2FwM X-Received: by 2002:a05:6359:310f:b0:17e:bb52:927f with SMTP id rh15-20020a056359310f00b0017ebb52927fmr8269823rwb.1.1710801381909; Mon, 18 Mar 2024 15:36:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710801381; cv=pass; d=google.com; s=arc-20160816; b=BRFY5e7ccQ0EJ1LbA3xI88foihKjeNFngTl6fSNybbDg1NYI2zcIPSlNfPPF9bP2I7 C98sc+wU7gNBR7yjTClbtegrc26E6fqNdA0A5Re7DwDTNvLi8zB5Sp4r/u+UgR9HLrwp HrJwOwvBFWyCXOS0jEFQVXO5xXYsWHSdBTJrdIt0jmA1I9a7zjOHucBJYIbu6Z/WXZ2C /fqFE3+JwaeyOLUocnPRfOa6GPnyLuAjGeH322mgGSa3dW31EYPL21l/Ag1aX/84l6OH Kz3B0C+zUZ77L+S9+oRcwYHPVDATNDzXhhL8fL8Ltt/H+jfS74hPxISFvEX7bukJmGrY JBxg== 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=QFNImd0Mua9KCTvHqQYaKAK0qurjGIisgRUAJ+l3grg=; fh=N8igrbvI7XB1N0lMiF8cTakyj7UDoR5EM+EZagPplR0=; b=JOb7hLpCCP9Pn1HVu/eVAnzVfCpDlqnCdOMJ8h6/sLS5yu6QTEgz4y26EYi+DLkT64 Cn8sCY1ZsumEJgi2WADObczvlVuOjyv9YA0Pgy/kvCVOSCJ902JnJuw+QVNoh2PdOHXF YjhkGLz+fNwlBXZG2a6Ol3fo8AtOp4kUpQVYxPEvWTHTD901iKAG/4OjITnvRFyP7v0C 8RhQa0GKnfiijR7K8Sd5rQynnWo0Q3nsduBXUT1xEQvVHH3s1WEQhx/eE30AwZMrC4ZK J3GDZZHB8uunkDXqdxbYqP9x2pMhligXE/4lhFSPWsLOaReqwZrN/d9IiRC9Ff7452aX P5Pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eVag+b1G; 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-106755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106755-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jw35-20020a056a0092a300b006e48649bbe3si10572657pfb.343.2024.03.18.15.36.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 15:36:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eVag+b1G; 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-106755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106755-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 8C6122826DC for ; Mon, 18 Mar 2024 22:36:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDB4D5A793; Mon, 18 Mar 2024 22:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eVag+b1G" Received: from mail-il1-f202.google.com (mail-il1-f202.google.com [209.85.166.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 5F6AE5A4E2 for ; Mon, 18 Mar 2024 22:36:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710801373; cv=none; b=Q4Ik+1drX0drSt2IsXkMo2hzTEixIv7tXCAgjDL4P8uF6C7a8lrFzUKuj8JR/GIY977/BByAbbdPztWVhyEl4WGl6KtY/FhTFSe6yMfLpLjmhQreyzMECSZ5XAyWJL7JTikaxr/vMIoz8jYsMWDp7ZeoShBsOU/QTuYlsEB+/BU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710801373; c=relaxed/simple; bh=idLQG0Kr6yCd5IwGaKvpKO3VhPnelbfggT+hRhuZhCo=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=JJinLfyZM3ezvPAb8dqPlvrHnf8iDCh4ZiI767OM3Y6ZN6onvbXTn6q/zJ4GnzQ41IohgNjz+EJqjUejMVgbbDbHLLiMhkjuCGcR+SH03o8x5Nj29I6NnkhtGPAwj3vFf59Sazkabcxqzd6C2MLZw6s4s6YJFWJn+2IzG0thEn8= 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=eVag+b1G; arc=none smtp.client-ip=209.85.166.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-il1-f202.google.com with SMTP id e9e14a558f8ab-366999e233aso23318865ab.0 for ; Mon, 18 Mar 2024 15:36:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710801371; x=1711406171; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=QFNImd0Mua9KCTvHqQYaKAK0qurjGIisgRUAJ+l3grg=; b=eVag+b1GKJedkBBNZlW2rtvYKXx0NRe6cJhBMa4jzvNFb1SREmsHKCh+jcMPbeUtR7 0YGlY+dp4NaFUaV8KSFYznAqYZVRhgaIqw2TGqlGQUW8DHWAozSIxApdcQXuUNQymxvp hWgx6DQBVkrVl10KtK59PCu38Gqvoh19nCuNJuY4dTcFLhBvgCFVJXj4nFJp0TgEWbAD L26tR9aWqW3zXvYRgnYq6/k/Gu8x15BdUqnGbQVBIctHXey2Oli26+uc27bpHsZjzdSU MvUc7QUNU4cRqJ0f0+Qs/kwAcEDZS93A47JQVu88dS5CYzRoKEWDTCXVtBsN7y0FNVtW 3qGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710801371; x=1711406171; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QFNImd0Mua9KCTvHqQYaKAK0qurjGIisgRUAJ+l3grg=; b=UNDyW9B/T+N6iN7fNGPZZ59M+E7Vd+stnFWIMhMyh2pNXl6/s9RvKp3GHxE3+4OkCX GzYVlCFJtywQ0lmqJuinCFhXCyuGmtNKzy0CBCRpcSd1XRaAXtuDME+Q9h8JK5RawQ/t jqIZExUi8JA5CZk59rqX9UF2RH44V2I8YaSrrF9V0jcNJ7NLCBc8Lh9YyCBmiF0lFcx3 MGAlJdRuiYO+OP0grdGN9PMjv8EgcQgObpWgPUXbW7sfZOctCmW4h2D4/ABR4FoRIsKz P9Tq65LuODFzirxs9ugFQe4TtYsAMDk8RgB1iPH10+3I5fUODTPm0hSfRxXyfJRqY4sC OZEQ== X-Forwarded-Encrypted: i=1; AJvYcCWjp6N+9cao8Emu2z9Dd4Anh2frv+ihxHSD/P0jJOLS6z2LlwJ0f5P5ZSkrSD1HrDKKoVFbYvTHgbEvfUn506Jn+Jpq9FhHgFmOxseB X-Gm-Message-State: AOJu0YwgIgPCgwIGSONhfYQOAuv18IwTtZMzDAIAB+Ghr1tI2D480jEd rybZzGxb16WquD1F3VWA4/ecZnQ3iUOLrkHhBRfK6iI/inOSOfAxh9HSaoib6OG2QNrBNNn1kN6 QH3tA+cIz3UmCsdZ2/93/Mw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a92:d68e:0:b0:366:a780:5cb2 with SMTP id p14-20020a92d68e000000b00366a7805cb2mr8306iln.2.1710801371403; Mon, 18 Mar 2024 15:36:11 -0700 (PDT) Date: Mon, 18 Mar 2024 22:36:10 +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=H4sIANnB+GUC/zWO2wqDMBBEf0X2uQu5gaW/UoqEda0LbRo2QRTx3 xsEXwbOcGBmh8IqXODR7aC8SJFfamBvHdAc05tRxsbgjAvG2zuWqonyhqPKwlqwzqzf+EFJlc/ 0wazD1UbKcsGgTSC0vekNWQ5u8tBmsvIk63nh+TqOP7za5QuSAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1710801370; l=2621; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=idLQG0Kr6yCd5IwGaKvpKO3VhPnelbfggT+hRhuZhCo=; b=+HXAnO3jukdE7ZFNa382FaAh2WDE9BnHodEf/wlzTo0fxNc6RJaEx+xFSV5aC0t4hXJSjrzfF 7wkRpBum/gAB2Evhh4ej0JRMWcC31tyDBUFqUe/bafGVYiWfQDB5PQ1 X-Mailer: b4 0.12.3 Message-ID: <20240318-strncpy-drivers-thermal-intel-int340x_thermal-acpi_thermal_rel-c-v1-1-08839fbf737a@google.com> Subject: [PATCH] thermal: intel: int340x_thermal: replace deprecated strncpy with strscpy From: Justin Stitt To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba Cc: linux-pm@vger.kernel.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. psvt->limit.string can only be 8 bytes so let's use the appropriate size macro ACPI_LIMIT_STR_MAX_LEN. Neither psvt->limit.string or psvt_user[i].limit.string requires the NUL-padding behavior that strncpy() provides as they have both been filled with NUL-bytes prior to the string operation. | memset(&psvt->limit, 0, sizeof(u64)); and | psvt_user = kzalloc(psvt_len, GFP_KERNEL); Let's use `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. 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/thermal/intel/int340x_thermal/acpi_thermal_rel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c b/drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c index dc519a665c18..4b4a4d63e61f 100644 --- a/drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c +++ b/drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c @@ -309,7 +309,7 @@ static int acpi_parse_psvt(acpi_handle handle, int *psvt_count, struct psvt **ps if (knob->type == ACPI_TYPE_STRING) { memset(&psvt->limit, 0, sizeof(u64)); - strncpy(psvt->limit.string, psvt_ptr->limit.str_ptr, knob->string.length); + strscpy(psvt->limit.string, psvt_ptr->limit.str_ptr, ACPI_LIMIT_STR_MAX_LEN); } else { psvt->limit.integer = psvt_ptr->limit.integer; } @@ -468,7 +468,7 @@ static int fill_psvt(char __user *ubuf) psvt_user[i].unlimit_coeff = psvts[i].unlimit_coeff; psvt_user[i].control_knob_type = psvts[i].control_knob_type; if (psvt_user[i].control_knob_type == ACPI_TYPE_STRING) - strncpy(psvt_user[i].limit.string, psvts[i].limit.string, + strscpy(psvt_user[i].limit.string, psvts[i].limit.string, ACPI_LIMIT_STR_MAX_LEN); else psvt_user[i].limit.integer = psvts[i].limit.integer; --- base-commit: bf3a69c6861ff4dc7892d895c87074af7bc1c400 change-id: 20240318-strncpy-drivers-thermal-intel-int340x_thermal-acpi_thermal_rel-c-17070c1e42f3 Best regards, -- Justin Stitt