Message ID | 20230528230351.168210-2-luzmaximilian@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1199595vqr; Sun, 28 May 2023 17:13:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48kD4av4GyqjyTeV1Zv/f+wC5kncwDKV70SxD4QPrpBOnRNQtg9mivl405FHuKlAPHF3aK X-Received: by 2002:a05:6a00:14d5:b0:646:2e83:6b2e with SMTP id w21-20020a056a0014d500b006462e836b2emr14218765pfu.31.1685319184588; Sun, 28 May 2023 17:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685319184; cv=none; d=google.com; s=arc-20160816; b=ALCLyduzOa83XL2l086tpwraPkQ9YzmYziHBTrRhie3+Btzr/rUWDYH6CP+VS/N4oY Gw+r4lx9nKyOLy8XjDuQW4SqYkHQxj/EQzC6x/wzzK0f3n6YBlWBV0zCAWtdvNC9qGOU G/2HPiVsUgZcPC7UIEb9A0K2ZQTX9m5ANhVdvgbBV2JIEicxOitzlg8g92WFd671dQqi dNRPC8YCDro1lnmdpims7Jin9StSUUVKDrTHK+7A4kcQddTyx+gofpMXBokn30neecqU nFghiDp3jtQRlnIwVLQB6I9NIMml1qba8ljdl3HXtowOYRIIjLLNt0Eo87Aug7dFY+5O 8FGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5nt4lk2LvorDlMmUZwioYE8n8ogEyIKWM/rXoeA3RL0=; b=jCTk85RHbZ6LpsnWktOLgZCTg9cXSEPNigMXett5ewW2b6qZE0scapy8hiN4OfAIZJ EeTbBznwGs7HL3ihzqwnQSG4RH4jMfqoSp1fcRtlnSHPHQJKoWQ4Jj8L1AwnNhpjdiYX gRQ9hgiJaoe967JYRnWuo7FtlNUkNhN3gIv60YITxG0jNG/VnszKpvfOXRQAaHaE5p4G tNmusVVnPKd+C14d6wY7cJ9Qs5uQLlvSGoY5/Vlm4oSaLlKeOB1DrkqGWP/fAAUltXKH LQ9TeX17Wex7B45M4hk1Ub5e0sMQzLfZon3e2Dt6KQyweabenl80T6X5mESjKauLUSEN vVIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OF8IKCHu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k133-20020a633d8b000000b0053b52fed717si8268028pga.864.2023.05.28.17.12.52; Sun, 28 May 2023 17:13:04 -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; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OF8IKCHu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbjE1XEG (ORCPT <rfc822;zhuangel570@gmail.com> + 99 others); Sun, 28 May 2023 19:04:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjE1XEC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 28 May 2023 19:04:02 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65861BB; Sun, 28 May 2023 16:04:01 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f6da07feb2so28240085e9.0; Sun, 28 May 2023 16:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685315040; x=1687907040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5nt4lk2LvorDlMmUZwioYE8n8ogEyIKWM/rXoeA3RL0=; b=OF8IKCHu66uXUYZ+syto9KLzQ3+6k9rwh6zX0zoHnpv76t2lagTmuKbdav0WKorOAY yGN4PcsXv6OxlfU51bncHDxmJqhCqk77beKAjBd4lOOeRc5ELFTHg9X4hj4kawn4qIS2 YJ7uu01R0pCz/7sClmGED0fgQvEYBh7jXoH8t51hI8tLGAuZh+uL1bAxYXbB/LQiDGfi B3r60G7Zipbee3pgSOEwf9YhoRgCPa6ZJbS+pt/zc7dDQdtFfdIs5wzd0y2BgF6EeNAc gSwuJh9/DPHsKN7cp3y5kM45Wu0RYPS/cLffEANfFJv9a/bQRh2KrLA/ievJUthXSllL ATAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685315040; x=1687907040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5nt4lk2LvorDlMmUZwioYE8n8ogEyIKWM/rXoeA3RL0=; b=a0JU3+gjHPAAYF/GA2uE4pDQkblpfg3lj8i78j87+H2fhSZLsH/Me/DxCxGXuSj4Cv 4wgQGme23bYmXHP5MrJHppYnIdpCLmlZpZyk7SLnKjsnhSMDdJD0gEzKXSbLWRiCUroC cCC5Qrj6mojXFMFlCzuixbdRZqEaeS4YdxwowARc9h8VQH2KbEegFrVFbKkEt2Vkm4sf SsY9IEcTXjaB7D8ava2YgeAJqVDPwKGLl+3pas0+o//OycnhEvGNfxIYqWw6CgwyWjWH fIQGN3dxHRrTS8m2+UogqoUdmS8aZTuVZQGk0MXSSVOnA1Q0MX537sZTI2nW0miV/wF6 JpQg== X-Gm-Message-State: AC+VfDyeQ4TAXd3Ae9KFUApG6krf32Qw8pBnqfjVQSo0kbGgpD9+n3xc ML0/I9DThJW623FboQpZ4UY= X-Received: by 2002:a05:600c:2197:b0:3f6:787:5e53 with SMTP id e23-20020a05600c219700b003f607875e53mr8013345wme.20.1685315039577; Sun, 28 May 2023 16:03:59 -0700 (PDT) Received: from xws.localdomain (pd9ea3c90.dip0.t-ipconnect.de. [217.234.60.144]) by smtp.gmail.com with ESMTPSA id 24-20020a05600c22d800b003f4e47c6504sm15995411wmg.21.2023.05.28.16.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 May 2023 16:03:58 -0700 (PDT) From: Maximilian Luz <luzmaximilian@gmail.com> To: Bjorn Andersson <andersson@kernel.org> Cc: Maximilian Luz <luzmaximilian@gmail.com>, Andy Gross <agross@kernel.org>, Konrad Dybcio <konrad.dybcio@linaro.org>, Ard Biesheuvel <ardb@kernel.org>, Ilias Apalodimas <ilias.apalodimas@linaro.org>, Srinivas Kandagatla <srinivas.kandagatla@linaro.org>, Sudeep Holla <sudeep.holla@arm.com>, Johan Hovold <johan@kernel.org>, Steev Klimaszewski <steev@kali.org>, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/4] lib/ucs2_string: Add UCS-2 strlcpy function Date: Mon, 29 May 2023 01:03:48 +0200 Message-Id: <20230528230351.168210-2-luzmaximilian@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528230351.168210-1-luzmaximilian@gmail.com> References: <20230528230351.168210-1-luzmaximilian@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767185249604984073?= X-GMAIL-MSGID: =?utf-8?q?1767185249604984073?= |
Series |
firmware: Add support for Qualcomm UEFI Secure Application
|
|
Commit Message
Maximilian Luz
May 28, 2023, 11:03 p.m. UTC
Add a ucs2_strlcpy() function for UCS-2 strings. The behavior is
equivalent to the standard strlcpy() function, just for 16-bit character
UCS-2 strings.
Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
---
Patch introduced in v4
---
include/linux/ucs2_string.h | 1 +
lib/ucs2_string.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
Comments
On Mon, May 29, 2023 at 01:03:48AM +0200, Maximilian Luz wrote: > Add a ucs2_strlcpy() function for UCS-2 strings. The behavior is > equivalent to the standard strlcpy() function, just for 16-bit character > UCS-2 strings. Eek, no. strlcpy() is dangerous in multiple ways[1]. Please implement strscpy() (i.e. use strnlen(), negative error on truncation, etc). Additionally, it'd be nice of the ucs2 helpers here also implemented the rest of the CONFIG_FORTIFY_SOURCE mitigations (i.e. checking for source and destination buffer size overflows at compile-time and run-time with __builtin_object_size() and __builtin_dynamoc_object_size() respectively). -Kees [1] https://docs.kernel.org/process/deprecated.html#strlcpy
On 5/30/23 17:25, Kees Cook wrote: > On Mon, May 29, 2023 at 01:03:48AM +0200, Maximilian Luz wrote: >> Add a ucs2_strlcpy() function for UCS-2 strings. The behavior is >> equivalent to the standard strlcpy() function, just for 16-bit character >> UCS-2 strings. > > Eek, no. strlcpy() is dangerous in multiple ways[1]. Please implement > strscpy() (i.e. use strnlen(), negative error on truncation, etc). Right, make sense, thanks. Somehow I missed that the kernel has a better function than the C stdlib for that... > Additionally, it'd be nice of the ucs2 helpers here also implemented the > rest of the CONFIG_FORTIFY_SOURCE mitigations (i.e. checking for source > and destination buffer size overflows at compile-time and run-time with > __builtin_object_size() and __builtin_dynamoc_object_size() respectively). I can certainly try that, but I think this might be better suited for a follow-up series, given that we then should also add those to the other helpers. Regards, Max
On Tue, 30 May 2023 at 18:15, Maximilian Luz <luzmaximilian@gmail.com> wrote: > > On 5/30/23 17:25, Kees Cook wrote: > > On Mon, May 29, 2023 at 01:03:48AM +0200, Maximilian Luz wrote: > >> Add a ucs2_strlcpy() function for UCS-2 strings. The behavior is > >> equivalent to the standard strlcpy() function, just for 16-bit character > >> UCS-2 strings. > > > > Eek, no. strlcpy() is dangerous in multiple ways[1]. Please implement > > strscpy() (i.e. use strnlen(), negative error on truncation, etc). > > Right, make sense, thanks. Somehow I missed that the kernel has a better > function than the C stdlib for that... > > > Additionally, it'd be nice of the ucs2 helpers here also implemented the > > rest of the CONFIG_FORTIFY_SOURCE mitigations (i.e. checking for source > > and destination buffer size overflows at compile-time and run-time with > > __builtin_object_size() and __builtin_dynamoc_object_size() respectively). > > I can certainly try that, but I think this might be better suited for a > follow-up series, given that we then should also add those to the other > helpers. > Agreed. Let's log the followup work as a kspp work item, no need to make that part of this series. Thanks,
On Tue, May 30, 2023 at 06:17:35PM +0200, Ard Biesheuvel wrote: > On Tue, 30 May 2023 at 18:15, Maximilian Luz <luzmaximilian@gmail.com> wrote: > > > > On 5/30/23 17:25, Kees Cook wrote: > > > On Mon, May 29, 2023 at 01:03:48AM +0200, Maximilian Luz wrote: > > >> Add a ucs2_strlcpy() function for UCS-2 strings. The behavior is > > >> equivalent to the standard strlcpy() function, just for 16-bit character > > >> UCS-2 strings. > > > > > > Eek, no. strlcpy() is dangerous in multiple ways[1]. Please implement > > > strscpy() (i.e. use strnlen(), negative error on truncation, etc). > > > > Right, make sense, thanks. Somehow I missed that the kernel has a better > > function than the C stdlib for that... > > > > > Additionally, it'd be nice of the ucs2 helpers here also implemented the > > > rest of the CONFIG_FORTIFY_SOURCE mitigations (i.e. checking for source > > > and destination buffer size overflows at compile-time and run-time with > > > __builtin_object_size() and __builtin_dynamoc_object_size() respectively). > > > > I can certainly try that, but I think this might be better suited for a > > follow-up series, given that we then should also add those to the other > > helpers. > > > > Agreed. Let's log the followup work as a kspp work item, no need to > make that part of this series. Yeah, that's fine. Can you please open a KSSP issue for it so we don't forget? :)
diff --git a/include/linux/ucs2_string.h b/include/linux/ucs2_string.h index cf3ada3e820e..ffd2a3ed84bb 100644 --- a/include/linux/ucs2_string.h +++ b/include/linux/ucs2_string.h @@ -10,6 +10,7 @@ typedef u16 ucs2_char_t; unsigned long ucs2_strnlen(const ucs2_char_t *s, size_t maxlength); unsigned long ucs2_strlen(const ucs2_char_t *s); unsigned long ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength); +unsigned long ucs2_strlcpy(ucs2_char_t *dst, const ucs2_char_t *src, unsigned long size); int ucs2_strncmp(const ucs2_char_t *a, const ucs2_char_t *b, size_t len); unsigned long ucs2_utf8size(const ucs2_char_t *src); diff --git a/lib/ucs2_string.c b/lib/ucs2_string.c index 0a559a42359b..f474c6b2fe9e 100644 --- a/lib/ucs2_string.c +++ b/lib/ucs2_string.c @@ -32,6 +32,22 @@ ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) } EXPORT_SYMBOL(ucs2_strsize); +unsigned long +ucs2_strlcpy(ucs2_char_t *dst, const ucs2_char_t *src, unsigned long size) +{ + unsigned long ret = ucs2_strlen(src); + unsigned long len; + + if (size) { + len = (ret >= size) ? size - 1 : ret; + memcpy(dst, src, len * sizeof(*src)); + dst[len] = 0; + } + + return ret; +} +EXPORT_SYMBOL(ucs2_strlcpy); + int ucs2_strncmp(const ucs2_char_t *a, const ucs2_char_t *b, size_t len) {