Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp204270lqj; Wed, 10 Apr 2024 08:10:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRcNqmp5HyRi7OAQy9srX1I+SI801s/MbN2u32tqGpB5IGEKTPt4xconxviVRZRNwH8TalvTet8Z+mB+u36MpDqDQaztAkOe7INEVEbQ== X-Google-Smtp-Source: AGHT+IGT1NF6gtbK+KhVhShQQk/5IprX/pWqJO+H+6WLCr6Q1Hbflxn57dyCm/fLAKxBDl+MOlcj X-Received: by 2002:a05:6214:500c:b0:690:c7a5:1dc9 with SMTP id jo12-20020a056214500c00b00690c7a51dc9mr3079790qvb.42.1712761809873; Wed, 10 Apr 2024 08:10:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712761809; cv=pass; d=google.com; s=arc-20160816; b=ZehZpKP6NAiffSDAgSBAg+miietROi6TI2xuWQHbafhxWh5SOGJkAHQ9gb88W+6qKo SZFm6rWdVB/qMBcPLmYmmtc/E4rJO4unNw789Hk8WhkE34UZlHsMWaEJdNAvJ4gmQOQW JoD2vIUjivhXKOv6+9V2X/D6P8ea4MjPmM9KPZ8qGbzSS8LtfRBV6jtRcxiClDACx7BL mY8qd9Kz+ACaXn/DRMmUfWKo1UE8qIDDZwLFI3rGb2OunzXP4UMkflc4ESC178p3hAKl e508UcP28S/Dt/I//8p9C3rnB4IdAR0DSO5D12QgDEbMsiehIGYmZDJQNftAjY0+0BRz c3MA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=Cy4xebQzWg8ALuOLJMZcZOAIDsJ9HQugVvvvnFO1U9g=; fh=4zArYmw4k2K+t+kjHRFBHNcibr3ytcUiBuvuZVh7nRY=; b=ZNKpa9Ct86HBxmXu2c3HtfljL2EQ+GXjVww4Zrxxd5YWUMFynNDMrZeDK9zfmveMs+ bgyQZYL6Iqe0ePYP0zec0Tg6pyY93EF/NeJ1YtSdjNFIt3FbS+9zmXNIPstkxnzuySgN ogQcrbTkyy1+8Tm9GVzmdkQJjZVQlCERWRxX0ivr26DKB5U7PnBLUFfMTUOLAuaR7WVf hYAm9Vhdq3h9gTjMe9yAeL8QFSob3jHB9NbdwlYivrGUx9xqueXpHPrMQUJbjGiUjE3G LjSKEpC+XxLpWRoLGUJR+kaoGQVJk7ZS4qazu50I+hsonq5xhvyasMDKYTZhf78ObWYW fKlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gyujga+H; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-138845-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138845-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f6-20020a056214164600b00699132af4b4si12458464qvw.614.2024.04.10.08.10.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 08:10:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138845-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=gyujga+H; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-138845-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138845-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 95C351C21B40 for ; Wed, 10 Apr 2024 15:10:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F6AE16DEDE; Wed, 10 Apr 2024 15:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gyujga+H" Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B852A16D9D6 for ; Wed, 10 Apr 2024 15:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712761800; cv=none; b=EZHmY7evIN7XywZUMvIEbI79PdHiNfIkd4SiB6j4MOK5uOb465UTrBiN4kQgCfaS/P5GwQQIoZkGCLHQOCGwLsYDLkZoBmBI01cWXqU0j+tjv6WjYyvTR5Dyxr5a7yRn7Df3uI6tqN4v1GxTYi7uaSMm4HGQREswte4ldQtk0FQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712761800; c=relaxed/simple; bh=JBToPHsKyA1IBRYoalpk1N7HunyLQxVk5LEZ5W4MlOs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Qg0xXNRnKVRQ7jbShKsAjC05aBjce7U6Y/n948udiblO0CM4TY+8VA261xYEq0/4jBw4sF4D5NMuKlzBGPatuLCNVFcRru+wkSkCT+e6aGRrjIANhMFRMzHgEF5LQl3ee0XiJjXC0Pdl2g9KyMffdKfZ/0emnNxHPenIOGycpP4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=gyujga+H; arc=none smtp.client-ip=91.218.175.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <4bfc3494-a3e9-4b4c-9d93-fa1049a10235@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1712761795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cy4xebQzWg8ALuOLJMZcZOAIDsJ9HQugVvvvnFO1U9g=; b=gyujga+HaZvsTQ7G3DmgTeft/hcI9fL/iS3AKqRtU5+stijNTdql8qDujHFNsjLn8ti84u LaATm+Wy2MzAHhA6g3V5ezs1I5QHVmJxvhUjpyeVBtlJdHU/Q2ueaMlrY+dJMoldGCfTYB ojlT6FDWBvgWlw+0ANXTkxkOOiKzkc8= Date: Wed, 10 Apr 2024 08:09:45 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] bpf: strnchr not suitable for getting NUL-terminator Content-Language: en-GB To: Edward Adam Davis , bpf@vger.kernel.org Cc: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, martin.lau@linux.dev, sdf@google.com, song@kernel.org, syzkaller-bugs@googlegroups.com References: X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 4/9/24 5:33 PM, Edward Adam Davis wrote: > The strnchr() is not suitable for obtaining the end of a string with a length > exceeding 1 and ending with a NUL character. Could you give more detailed explanation with specific examples? I think strnchr() does the right thing here. Note that if fmt is not NULL, strnchrnul() never returns NULL pointer so in the change below, 'if (!fmt_end)' will be always false. > > Signed-off-by: Edward Adam Davis > --- > kernel/bpf/helpers.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > index 449b9a5d3fe3..07490eba24fe 100644 > --- a/kernel/bpf/helpers.c > +++ b/kernel/bpf/helpers.c > @@ -826,7 +826,7 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, > u64 cur_arg; > char fmt_ptype, cur_ip[16], ip_spec[] = "%pXX"; > > - fmt_end = strnchr(fmt, fmt_size, 0); > + fmt_end = strnchrnul(fmt, fmt_size, 0); > if (!fmt_end) > return -EINVAL; > fmt_size = fmt_end - fmt;