From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 3CD78219E8C for ; Mon, 1 Dec 2025 18:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764614920; cv=none; b=Y7sOr1ZkDUmdNuQ2bNXwn7WHPuH/fzIbZ9VG7/nQqjTBNlVbh/wcZV/LHdpHWd0WG79Abljh5RBr5/w9e+aJlcb/uS8HReeYLBj0KcfuwG3gDjNMnzTq4/+phyC3edeeWJVQVsGWI1DAPL0hVIgKu8BMEW7iwnWFUfnk57S9638= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764614920; c=relaxed/simple; bh=CnfhMURLCP5gRu/Vrz9Z8ry7dgu8WYAjKRHKa+VVXaA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IWI85qoR7Sgo0rtA0JE/stnei2P7no9mNGBSvkBi+WJ6UWVPDZ6329D95HWVtCOKU0SY9R4k7M9CBew25MFt+hsrKK7RTR1X0js81E4OQIVIh2lBQee0gGDTEY+Ijxgl+uFk//NKYWwA/JeErd+BuGj9faUUSEhkmo/7k8+yOos= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zt0F4DGZ; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zt0F4DGZ" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-640b0639dabso8153110a12.3 for ; Mon, 01 Dec 2025 10:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764614918; x=1765219718; 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=ZpfWqQh/CZVZrTLcwqyUSpbKiv1XUQTOI1ALBgTqqvI=; b=zt0F4DGZ4ZMRna/OkrDQum4+KXCfr0LyCmUs1tjukY0fQoUZZv+JOf/92yf4PDk9m6 Hs/nkFwsQ+q2Xr+q3yKOSeJPHLj3DxzsqKcZlhxUL1+bMfrNa8RuHDYnokYOm9hloCsJ BTlFiCWCZ2lf20aIDobB9mv8Xs+chcYKzvK+Benz1FkKAK7V3rELcm0+VISnnOtL9gjR cc3bMnT2U5tpmLQ9MBG6iv9qPvjSB+5raKv61Ga1b528pteDmLB9VCOPn0/JeQftMRBy VEFRMLOefwhPChBvFhvg4apiMu+zUTg6+b4M1anb+ct5taswd10UwcC3krJlwcv75rGG XAvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764614918; x=1765219718; 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=ZpfWqQh/CZVZrTLcwqyUSpbKiv1XUQTOI1ALBgTqqvI=; b=Vb/+MlNM1h/pf6MxYL57kx5K+BupEaffVMEu4wsQmk5ru49+Y0oPIOd976dJDTkA1h spC+/pwC9VHyAqV1B6NWYGT+4eXmN9543FSOUnYqDjrAh5/RK7kgKerz0/32LXhabJia Gn9nSwmFPiKlBHKgy6sF4HqbcOnS1qjqQp3hEXkasG/4LLznpf7oC6DPOHg0j2C10Z84 1tFGKviN9uiCV4soUSoYlC4o/V5otA16lxPL5c27vlQhmYDNC9E5IOKQugOukNeD59eW cmY01e3Q9n+GM21k0Fysj9mdR7TGR78vGoS0qk2+q/wsIZdYALMyONIbcTwyQ5G7ULK6 xfEg== X-Forwarded-Encrypted: i=1; AJvYcCVjqFex529wKEXszs22XgXPFpjYAWo8kJzKmEEqe0AvgJH0h5Y8fsTVeeF2/ix0X6N9w9UhbrtdEbzWjdo=@vger.kernel.org X-Gm-Message-State: AOJu0YyUmvymWYByQYXDCAHeHXEwf3nIroSftKmfkdNckMyU4LPwZlO1 4mdbP0uIt/EEiDJsLrgadF0UJ8BzKzMvZqXdl1TRIwEZLQg0XMpEtm/SaEHswB9bTw== X-Gm-Gg: ASbGncslzWlAxboxdA8Yn35rUPIlQ6xecT5xoYPIzg4IVnUg9UY6GO7s8LnjfH+vdwV cJWmUW6AGFCe3VFbevMICKIRcmMVGSDlkxko/DonbdjGwBLpbLCv8Ik/Y8ZMHAvBLmQugxRlCQd HC7/UolfeRQakgtPpzptJ8tm5inOJLgVbtUmX/wWycURDk+wk6V/JzEcnihtzCQkPVQL/q9VK/m PuEctGJoXRz713mRM+tUBMN+bobAUWRhI2mAsAwWaOFMH718XiQhFlpjE/uyc0j5CYz7MB3NI36 PePkUmTVPnw8oIMvczQ/4q9MPJZReqBuR79yudy8uBe5ri32LbqplHooZdklB6L/CupUGNXkq/h sxfILcA075L1RAIrgDTc/kMXUbZ74UIr8GovjpyaCrcgT51lFe+6SnkwicC0fHB5zcmnDcWyyZG GvdlDwivfGySV/ZDCeFA9J9VY470b/wXnaNtF3igfZ77EtYqa16oDT32XBhTA= X-Google-Smtp-Source: AGHT+IGmXA2mP0MtVnshtm+vBcsRlVLPNa1rL0RYJJvD58tPEKTOZlQjPjIiAfAy0yNT5MrN/ysZGg== X-Received: by 2002:a05:6402:3246:20b0:640:c640:98c5 with SMTP id 4fb4d7f45d1cf-6455469d112mr31462733a12.34.1764614917515; Mon, 01 Dec 2025 10:48:37 -0800 (PST) Received: from google.com (155.217.141.34.bc.googleusercontent.com. [34.141.217.155]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64751035b75sm14363010a12.20.2025.12.01.10.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 10:48:37 -0800 (PST) Date: Mon, 1 Dec 2025 18:48:33 +0000 From: Matt Bobrowski To: Shuran Liu Cc: song@kernel.org, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Zesen Liu , Peili Gao , Haoran Ni Subject: Re: [PATCH bpf 1/2] bpf: mark bpf_d_path() buffer as writeable Message-ID: References: <20251201143813.5212-1-electronlsr@gmail.com> <20251201143813.5212-2-electronlsr@gmail.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: <20251201143813.5212-2-electronlsr@gmail.com> On Mon, Dec 01, 2025 at 10:38:12PM +0800, Shuran Liu wrote: > Commit 37cce22dbd51 ("bpf: verifier: Refactor helper access type > tracking") started distinguishing read vs write accesses performed by > helpers. > > The second argument of bpf_d_path() is a pointer to a buffer that the > helper fills with the resulting path. However, its prototype currently > uses ARG_PTR_TO_MEM without MEM_WRITE. > > Before 37cce22dbd51, helper accesses were conservatively treated as > potential writes, so this mismatch did not cause issues. Since that > commit, the verifier may incorrectly assume that the buffer contents > are unchanged across the helper call and base its optimizations on this > wrong assumption. This can lead to misbehaviour in BPF programs that > read back the buffer, such as prefix comparisons on the returned path. > > Fix this by marking the second argument of bpf_d_path() as > ARG_PTR_TO_MEM | MEM_WRITE so that the verifier correctly models the > write to the caller-provided buffer. > > Fixes: 37cce22dbd51 ("bpf: verifier: Refactor helper access type tracking") > Co-developed-by: Zesen Liu > Signed-off-by: Zesen Liu > Co-developed-by: Peili Gao > Signed-off-by: Peili Gao > Co-developed-by: Haoran Ni > Signed-off-by: Haoran Ni > Signed-off-by: Shuran Liu Reviewed-by: Matt Bobrowski > --- > kernel/trace/bpf_trace.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 4f87c16d915a..49e0bdaa7a1b 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c > @@ -965,7 +965,7 @@ static const struct bpf_func_proto bpf_d_path_proto = { > .ret_type = RET_INTEGER, > .arg1_type = ARG_PTR_TO_BTF_ID, > .arg1_btf_id = &bpf_d_path_btf_ids[0], > - .arg2_type = ARG_PTR_TO_MEM, > + .arg2_type = ARG_PTR_TO_MEM | MEM_WRITE, > .arg3_type = ARG_CONST_SIZE_OR_ZERO, > .allowed = bpf_d_path_allowed, > }; > -- > 2.52.0 >