From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 D0F54314B76 for ; Wed, 15 Apr 2026 10:49:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250161; cv=none; b=UFICedCHgSclA4Dm0oROzY6pNw71q4OEX9hxtgF6vLjArU5tkBj/VTRw13GBfAxFMebKcqsu+uE/J2cn1p7C923KPTEw4Y487iiTpoDKHav87U9N3rRBJB4Po9aIPMeCG1iKzTUPnSXkOGZdCt1eboZEFieg5QibO0dtcRGvI7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776250161; c=relaxed/simple; bh=I14BmVJXxDlFKWq3Os4T8qNRubEmA8Q6L1/fdrYthtA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ool0vT2ekqoOZ5AKoLfvhSt5AQFGMa4w7AChfv3hph1UpcwSq/0GRb7sADsRzUukNDGVrFLM9o6BFyu4ty9cK/CatSIPwxebm4uL34FMhzlhvVUiY5XVK11zOgirn2sfltEtNjNJT8Iem+w7oRQb6GCgI/BG3XL2KB4BZXYVX50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fh8JYbuO; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fh8JYbuO" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-488b0046078so65272355e9.1 for ; Wed, 15 Apr 2026 03:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776250158; x=1776854958; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TZ9DolBx7oWdXo3o6819JtHACfT0Arv3+O2nQR4ONHw=; b=fh8JYbuOCDpbruvidBGWBQuBZYEKgfABTnvMaU9xKt2U368d/RKO85iGcStVv/vCXR JAKpRSyA+fS+WxHGoDEgx4+CkB97KIqj85t2XT6Yh6HsAaBI9ZPvfohH+C+6grrvDsOb ATke8z6NNQyfIndN8tDitiO1gVAiBoj4aQSNPKxyuuumZ9rQHqFfM6YALdR5AYI78TrA Gf+g4WXAQwrGfkrXtP+fzfVC5e0V1UdKPwh6mgZYtF0nvAiaV4c+fRGQ84c3QY4uaapN WgbDpwrNNdEko6p21Ojk6zo74pAzvcfxjR9SKe57hsGGinjF2izXnQN6SjuIm4ZXH1lg 3UiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776250158; x=1776854958; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TZ9DolBx7oWdXo3o6819JtHACfT0Arv3+O2nQR4ONHw=; b=gXCaSQxAZZ+a3ZE2rufCIoKH9gZRxcVLmoS7QCu2rkmD99RIxD02eT07is/H8ftMvE GkCd4qN6Z6zgDiq2150rsFPqXcFLVw8ePFE8PtPGvuAGgHtApy8n6c1YFUWXlovG4WiR J36bfWHGTTCzf7FGKl4aEKoJ36usPkhUmXvSd8njOOvHqw6lrBqyMKuPJwmlJlAxn2hv 1mZWImmLm0JBgl3REKDFlbycyMWNlNfNt/krLejw6BxsN1Abg/Yp4FhzpPQxLTAK1X/s sFKs6A6+6jCHkDjB7RS8ZL6Bj4TFdtuCv83JWmM57i5OtSIgAZA3tImW/Rd1RHMrsA6p GIcg== X-Forwarded-Encrypted: i=1; AFNElJ+ykA7C2fUulbnM7WP5VbHqIrrDA+TDFNVEtS+V/GEozX/H12uOTVwcZt3MUcOLv7hLh5BjkMfYIgLSVzY=@vger.kernel.org X-Gm-Message-State: AOJu0YzHiRVrB8JH1jLbMzGO85Egat1p0wfXDnl3W1raZJnrqOY2k9a4 06Asj4GRxB+YWS7vjcDve9iLwyO/FE4Pz3jL4Kp3AmYEUE3qy4/UuobG X-Gm-Gg: AeBDieuCbqIoL+RS/bGKLEUynI6oqAiznzeu20i9E8OzgEvYg0PH7CFgD01vnQ2uw6z g0Fnga69zZlQfZnjm907cxqnYePMiZbo+6L1CcZkf1QCUCNHlYbVCHoTLKf2LzsD8cbn6lFtELR UOS6DbpECLrDRg8SJN+ic/ao/FaCWFBA2xBy79EawxqhTek1WcfVD1nu0ykjYi9HTK/dJiksr58 eF1iHySWigcI03Y/344f7qEVGC5mrTaQyaZQZgn5vDi6rwISk2CoLlmDMgoPYCiuuyKBDV7rm30 8SiScPv/97O6GkUorJEOFBM0AVcNBrKTlwiz2TyDR9aPnO/eour9eABHxD8EuVlwVAEY2xgsR9k 6LgewUnGtwZC2JXKUtlz2saX6LhEESMt8z9G3EngR9tcyy5SVVxI6FRDiGMsIZfZ/sLBtUw8TUk 2giRx+62e9/MCR/yqJEWnKdrPNaCp1jIlQpD391ZGBzL+G/bQkaallwpzNIMH2efSrxIlck7LOr mBm65gCbXCokvyHql0DkZkqcuq0cTCsKxj9GeFXem0fnuoCUHe2D+7V6eRuRgN8ciXjJtopU2YE w8vO6MTBrpAIyL1ctwkVoOzz4etjrqvBtNU6FaFUZQOhErNDUUI+MQ== X-Received: by 2002:a05:600c:a109:b0:488:a977:8de with SMTP id 5b1f17b1804b1-488d6839866mr202485885e9.16.1776250158106; Wed, 15 Apr 2026 03:49:18 -0700 (PDT) Received: from mail.gmail.com (2a01cb0889497e002eae79bbf3d352f3.ipv6.abo.wanadoo.fr. [2a01:cb08:8949:7e00:2eae:79bb:f3d3:52f3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488f095ceeesm22206885e9.8.2026.04.15.03.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 03:49:17 -0700 (PDT) Date: Wed, 15 Apr 2026 12:49:15 +0200 From: Paul Chaignon To: Yihan Ding Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, shuah@kernel.org, linux-kernel@vger.kernel.org, alan.maguire@oracle.com, kernel@uniontech.com Subject: Re: [PATCH bpf v2 1/2] bpf: allow UTF-8 literals in bpf_bprintf_prepare() Message-ID: References: <20260415032126.1096299-1-dingyihan@uniontech.com> <20260415032126.1096299-2-dingyihan@uniontech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Apr 15, 2026 at 12:45:02PM +0200, Paul Chaignon wrote: > On Wed, Apr 15, 2026 at 11:21:25AM +0800, Yihan Ding wrote: > > bpf_bprintf_prepare() only needs ASCII parsing for conversion > > specifiers. Plain text can safely carry bytes >= 0x80, so allow > > UTF-8 literals outside '%' sequences while keeping ASCII control > > bytes rejected and format specifiers ASCII-only. > > > > This keeps existing parsing rules for format directives unchanged, > > while allowing helpers such as bpf_trace_printk() to emit UTF-8 > > literal text. > > > > Fixes: 48cac3f4a96d ("bpf: Implement formatted output helpers with bstr_printf") > > Suggested-by: Paul Chaignon > > I don't think this tag is appropriate here. If you want to give credit > for changes made after reviews, you can do so in the Changelogs of the > cover letter :) > > > Signed-off-by: Yihan Ding > > --- > > kernel/bpf/helpers.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > > index 6eb6c82ed2ee..6319b39c92f9 100644 > > --- a/kernel/bpf/helpers.c > > +++ b/kernel/bpf/helpers.c > > @@ -845,7 +845,13 @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args, > > data->buf = buffers->buf; > > > > for (i = 0; i < fmt_size; i++) { > > - if ((!isprint(fmt[i]) && !isspace(fmt[i])) || !isascii(fmt[i])) { > > + unsigned char c = fmt[i]; > > + > > + /* > > + * Permit bytes >= 0x80 in plain text so UTF-8 literals can pass > > + * through unchanged, while still rejecting ASCII control bytes. > > + */ > > + if (isascii(c) && !isprint(c) && !isspace(c)) { > > err = -EINVAL; > > goto out; > > } > > @@ -867,6 +873,14 @@ int bpf_bprintf_prepare(const char *fmt, u32 fmt_size, const u64 *raw_args, > > * always access fmt[i + 1], in the worst case it will be a 0 > > */ > > i++; > > + /* > > + * The format parser below only understands ASCII conversion > > + * specifiers and modifiers, so reject non-ASCII after '%'. > > + */ > > + if (!isascii((unsigned char)fmt[i])) { > > + err = -EINVAL; > > + goto out; > > + } > > Acked-by: Paul Chaignon Actually, this patch will require changes to fixup the existing test_snprintf_negative() selftest that is currently failing. That fixup needs to be in this commit to not break selftests during bisections. > > > > > /* skip optional "[0 +-][num]" width formatting field */ > > while (fmt[i] == '0' || fmt[i] == '+' || fmt[i] == '-' || > > -- > > 2.20.1