Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2167130lqe; Tue, 9 Apr 2024 11:20:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfXvFbbPNR8BzlU5q2zO0GbX8xzw7ghHfbX9NbsTodIADu081kn6hnGmv9WMMYktO9g8D35A2F++zjsjzYF6NzbacrignDo7hIKA1KZg== X-Google-Smtp-Source: AGHT+IGGTO/p8TJEWJFbjSv5iBZlQJcRICH+wc3RW05QG/emH4vQ1arBLEG0iQrHVbPnh08q9T0X X-Received: by 2002:a05:6a21:3286:b0:1a7:1c5:4746 with SMTP id yt6-20020a056a21328600b001a701c54746mr856535pzb.1.1712686842634; Tue, 09 Apr 2024 11:20:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712686842; cv=pass; d=google.com; s=arc-20160816; b=bd16vakzMlyv989nwB1KuijPj3tDTnYXUeiiU29Ew9XLXnhjX8eVo776tP9Juby3J5 6C0gfxD4Oinr/rigtNV6CVJD4U1dnQ7NCMCoHNUMsfxOGLG7YfttqHbGUx3vHCSXXDQB NXrBcB+giiwvwg76CTh9bMhLpY140qyVEwYu4Y4hlWhHErrS4pMXG5IKJsjgC04+RpGk G1ruGAZjPIwOtT+WS2pJKX1fsLNY+oM72Mqi5/DSn1NTkFkEw8GKQ9lE2sNW/ihvczUd PT19I8wccHniR5zUcuAJcEdgB5gveRxqadT+1+DXH5HsH7tiixMEezacCutBXFB5us5m tIvg== 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:content-language :references:cc:to:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=zFkudtkarTW9bOE2Z7rxixOdH6DWABVMAIpnLcA4MUY=; fh=an3DHlDYy/Q2d5QEmSBMRqZ58aus2ASTwiH1zO8Lk08=; b=Vd3kswueUNIw3lGoL27+rd0NLIdRWLzmWmca/irXUwsMbQLPO8ECdm/5Yiiexxwhbz Eux9FA+AAbFVaTFrSF31wFamjSeagb5/+bpHuBLGToiqdUg0BlbR2zNPlreEcMVbRxXe BYogNhlvOcDVXDdgXZxNcpCdnxJZvu6r577w+AcX2KIlD/L7fzv1Y0Bwjiu480Q66ABM HX8rdv/iXtrusACCyg2adfh/VCeJT78sQV8/iVBDRlVWWXWDnnzKeG3CNeKprQrn7Urp /AiFDUl+On17BINr8t/m5IdWtwakkoRcfMN8NYDSsT+p+05QoY+Jbcn+vdJuM6CkhD5A bHKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wH4GweWf; 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-137433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u5-20020a632345000000b005dbec97f04fsi9042639pgm.589.2024.04.09.11.20.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 11:20:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wH4GweWf; 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-137433-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137433-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 14E38B24C71 for ; Tue, 9 Apr 2024 17:59:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07BE5156892; Tue, 9 Apr 2024 17:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wH4GweWf" Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 04E594C85 for ; Tue, 9 Apr 2024 17:59:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712685569; cv=none; b=iqySgsQY6YesPPPJF62aYVjvsAkAxLjE/7rg3fee9dHjg/JhrpphU/3byzB1/ncQPLQEiM2zFCHr8wHgQDprLUDTZ3mfcaNO2F/Bs8hqyXODJqs4lsEO0WGnsjCbZHtK6RTr7WMY3PmGvMjgOld3E4kx8uFWpBQg+E2HdH84yT0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712685569; c=relaxed/simple; bh=gERIPEmSHsEjHilcpu5pXc4M9aGva12lLhXm8WmvYGg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oH4QYXtDdhGaYnP/4GH1rcp6fkwAoPk+c4asua6sIQlzZXzt+/YkSdH2TEhCxG1LV7WMvIhiO8CAOgnlr9YeIeZ7vD5cKeE5Qi2ogseFoVd3TvFtjCzMRJO0BItV6RJU9ONBBVVSDx5JSB8jvcdoRK9RhzCH6/mKn1TQgoKVzWY= 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=wH4GweWf; arc=none smtp.client-ip=91.218.175.186 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: <3cbc70e6-04e9-4523-9d4d-84d0794cfc74@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1712685565; 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=zFkudtkarTW9bOE2Z7rxixOdH6DWABVMAIpnLcA4MUY=; b=wH4GweWfwbyq3i1FND1UFOlCJxV+HUp0And7/LYWbsvjl9lS7xoCxPpFHqFxvU9jnSAz8r 7yTdp9511czlKCEKpWaV+NIJz4hZS1xlfGisVwUIECMyqRZcTfYFhLYq+akB55x7xUXKqn o9jdXl+py+52wsTvWpoSN6K0qu0ZHMc= Date: Tue, 9 Apr 2024 10:59:17 -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: fix uninit-value in strnchr To: Edward Adam Davis Cc: syzbot+9b8be5e35747291236c8@syzkaller.appspotmail.com, andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org, linux-kernel@vger.kernel.org, sdf@google.com, song@kernel.org, syzkaller-bugs@googlegroups.com, yonghong.song@linux.dev References: <0000000000009e2ff406130de279@google.com> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau 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 4:37 AM, Edward Adam Davis wrote: > According to the context in bpf_bprintf_prepare(), this is checking if fmt ends > with a NUL word. Therefore, strnchrnul() should be used for validation instead > of strnchr(). As your another email, this is not fixing the uninit KMSAN report. If there was a separate bug, please post a separate patch instead of replying to an unrelated thread and confuse syzbot. > > Reported-by: syzbot+9b8be5e35747291236c8@syzkaller.appspotmail.com > 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); I don't think it is correct either. > if (!fmt_end) e.g. what will strnchrnul return if fmt is not NULL terminated? The current code is correct as is. Comment snippet from strnchr: /* * ... * * Note that the %NUL-terminator is considered part of the string, and can * be searched for. */ char *strnchr(const char *s, size_t count, int c) > return -EINVAL; > fmt_size = fmt_end - fmt;