From patchwork Sat Jan 14 08:50:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 43716 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp194377wrn; Sat, 14 Jan 2023 00:54:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXvDnQlw754lvMWWN4uIcroeyOeFnqvB5Nhzer7NznqAvjIPsOZZ0I+uhQ/PnaTJOlUlBo9C X-Received: by 2002:a17:90a:202:b0:226:fa8c:e50a with SMTP id c2-20020a17090a020200b00226fa8ce50amr14510845pjc.35.1673686457561; Sat, 14 Jan 2023 00:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673686457; cv=none; d=google.com; s=arc-20160816; b=io3+HAbDpV/IhUPLVfk13kR03wp39ZW7xaD+c7wkSVGsN1mZmVbeMZR0u+5uxzpgbB VN9cwQ7N01dXQnw+n6flqLAz3xi07xuzYjgNXSDb2UTsd1px7JGIUfhLmRohRxLc/ghc yU4a+yzWwN0mV6KQCutIX8SodqANhFlObvsSPxnDpZQO/8woz72rqK9Q+1SwL9UA/RR+ cqcIXxJJSnQplg5BML3iwL2IPT58jmaXItSwblk2tXY+jvtAamP2Op+qd6FtZXQYaycD XnFFOrHAORk3Thvsliqlarkqx58SsXKTRSArfunHZtyOlRmEm3H+an6irnveMWh+mE8h wF6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iYrGvVtfb/qBpLe5Rz87ApLKZAby815kSImkqii6gKM=; b=kdATIHmFID1ZQInYcdVtZ+B6qu0mYTseKg6FyPiDgLli2oJp7yYhsOG5TFznoC+9HP 9aK7OZLUY39v+5MpoklmfgeBUdS3r+He5lVhqOiYP0pwdQk5LrvaQvx1zprtfdBdrfAC cizEZ+vM0vqKGhAHu8U8sQV5dyFO+LzTru9rhqNGtgped4ELV1chdGXBbt+PTJv2juiI CbN5aLctecRd+Iy31fzyrxbgTd/bblqQ0un0CT5oDeH6n5FxJlKoY3CEwdVVXisq3CB+ sToZ7iXmCrrPxFUrUkoyE5RsdNftAbQsf5WaURIrrq91Tqwhphoe4rT97ra3+hUJRB0g lxdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="jl/+AWUS"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v69-20020a638948000000b0047895cb1543si7021554pgd.874.2023.01.14.00.54.05; Sat, 14 Jan 2023 00:54:17 -0800 (PST) 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; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="jl/+AWUS"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbjANIvR (ORCPT + 99 others); Sat, 14 Jan 2023 03:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbjANIvG (ORCPT ); Sat, 14 Jan 2023 03:51:06 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 895856E84; Sat, 14 Jan 2023 00:51:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1673686257; bh=ecSPvHCNjAvVeCQzbDjFrZEbtxhwySp2CjVRnX3yiRY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jl/+AWUSgF3KF0rnllZ9T2SkWBIYgsomNDbLkujsOkL8IOaVDqeIATWN1TdUVgQNY gGamUDmP/FJSQa2xo1lNYRv2CmvVYhCJVErVkXwD2S+p/1k7UPbuto207VflvxFk5e rIr/2XaEt6vi5gTfEk7XohDJC+0n1JWULXDPSEzeCKYGTkfI5vcZzk+F1E/kLp8eGh pgMpAXE+J512DtY9yKIJD0/BwyYgiTZE81qnp163xI5+KSkM0mV0dTmWPh8HIyxksF hkXk5D9GUzMFq1OTYCwkdmM1MoSjzgS7TIo+uqvjWgvwapGH8lAGeL99EuYoevwpMi Lj1KxWhK5nBlw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MIMbO-1pUtS03vpE-00EJoI; Sat, 14 Jan 2023 09:50:57 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] ACPI: battery: Fix missing NUL-termination with large strings Date: Sat, 14 Jan 2023 09:50:50 +0100 Message-Id: <20230114085053.72059-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230114085053.72059-1-W_Armin@gmx.de> References: <20230114085053.72059-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Wnx0zZfkWOTNqc0y565JEVWCMcUdeD35UbCLS0wpCTRKXW7GKsx 3WiNFgzjgxLl18K3aaWZXQb7Lg0Dm6qGydvsVav90ct5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nLV 2S3S4n09x93bN5jKX0SJtJqwMyHd9a5F+JNzNx5unS9GX+Cm6VpTIfpk8REYrbhHw7vGnO1Vs nZCLtvg7XCPnxxLYxnU2OYVJs+E= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754987451166662779?= X-GMAIL-MSGID: =?utf-8?q?1754987451166662779?= When encountering a string bigger than the destination buffer (32 bytes), the string is not properly NUL-terminated, causing buffer overreads later. This for example happens on the Inspiron 3505, where the battery model name is larger than 32 bytes, which leads to sysfs showing the model name together with the serial number string (which is NUL-terminated and thus prevents worse). Fix this by using strscpy() which ensures that the result is always NUL-terminated. Signed-off-by: Armin Wolf --- drivers/acpi/battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.30.2 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index f4badcdde76e..fb64bd217d82 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -440,7 +440,7 @@ static int extract_package(struct acpi_battery *battery, if (element->type == ACPI_TYPE_STRING || element->type == ACPI_TYPE_BUFFER) - strncpy(ptr, element->string.pointer, 32); + strscpy(ptr, element->string.pointer, 32); else if (element->type == ACPI_TYPE_INTEGER) { strncpy(ptr, (u8 *)&element->integer.value, sizeof(u64));