From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 A0ABA2D2381 for ; Sat, 18 Apr 2026 20:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776543901; cv=none; b=WfV/iAU+d7TVsuamWj6nSMRRWkV/ipmhk2Q1Z2c02MmGRltD5mdzjCOc1C1fUh+tW8yzr+zN+ybXzdypcn2sZ0+E7GrK7eYYLg1l+CoPD59g93viwxD8zugMid18po8KaFP4fZCGzPiSRHwH9Mj4YibnzXAYLLDD6Z/KECXxfi4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776543901; c=relaxed/simple; bh=1TlQLg1hmyRIP5xa792cH1aj6284vPZu7SIqkmxkdqw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=E6wCKlEhDRpiPDqlR4iYd51JW4dxgy6+OkWkyl5EWkLmhPzk1XesClPC7qdVdr3PIKAsq8Dcplekb4js+sMZNfPbn6m9gBWL/t5wGDpxXEQu241akxLdpc6QxEgOkB5rlJ8UBYdX0HW6go6AIkKyD7UkNid4mWPlQCEFB1dg1Dc= 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=lgx4mwQ0; arc=none smtp.client-ip=209.85.221.44 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="lgx4mwQ0" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-43d0deb7ad5so1381791f8f.2 for ; Sat, 18 Apr 2026 13:24:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776543898; x=1777148698; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=shrpPgBn1ciDVC0UZRKGswrL54fyNSPIH9KuoX6GYKI=; b=lgx4mwQ0qgJV1nTkjvQVBxTwzV1yDOXdYIZv+H7ybaQ7hAZP/nx0nFeWzjAHyi6Ign cZ5vuoC0Gnt2+ZjzJouCI1fKphLFTE3jQ70g0MsiHPHIbuNh+VbcddRGlWiDV6UhJTLL n5n54/tpNdCbTZ6h610K+lEXgXbH0+Yz6c6AjU3rLMysgaVs7jOhFi8DzgfBkR3uUjxa tsUyOsdJD+SjuXlPOjiGoFZBm31VmnjFIT1HO37EdTNqicIVat1o2CVwrIVRgqoGMm5y IdPUVycm8Ofgg5S7QTLyVaqW71qTvLtj06cXKNqbL6q+p9Eu1Im1kBrG4cp8FFoW+NRV brYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776543898; x=1777148698; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=shrpPgBn1ciDVC0UZRKGswrL54fyNSPIH9KuoX6GYKI=; b=amJFBrwcadL/0px/JunehoflxAOashHUmeytVuzAaBLzv7vMmxFzTeS59Z6yOe7is7 g0f/kt1bwTV0sud53XKAMGut7OMVmB+7BB6/4Y6+nCIdBpN6aMdotbOfM0XRj4BHOWeN n3fJOnzr6zW7GACXeD/nZ1GEizJtzOw5SLJkrTM3mieG+afluUcHm99Rhtu5d86R1Eaf SEgb6R4XhMxAi4chQog7pJF2s4208stvDR09JFtlqfqgUjWJvVdVctJHWCvzBRdR4+iH Cy4csYQbJkaH0QmFLRLOm65hdHAJaMxH9nZVFZbgf+gdHhn6HBlVxcZMjPHE0SGJ3fvq 4djg== X-Forwarded-Encrypted: i=1; AFNElJ/Uq8pManzN4/y0t/akv8hywHysi6ZX6W34OcHaRLzYXTrFpCMYcXxTCFDuOoZ0zyaXR8BBFyHnmxWruXA=@vger.kernel.org X-Gm-Message-State: AOJu0YxGOvuNbvVk7hILY8WMvpMiW1pmbASetstHb/FvTWDKXNnnE/QY otlFpk8h7YyDoOokEm5KhQhvpSbFTlbXx3baaJSsPzhO40oV9HeAHLBD X-Gm-Gg: AeBDieuAniSn5tYfPeJ1j7MKVz9vAzPEJYbTya3ZvOmxQg/PUkZ8knkzfW3LIQjwuBg asZryqHmNGVeqdCu+Rbg1K5fVYSB3+842g2VOz3U+2CFo1oWkfYYAS0l+ZoppudFBFLAjfKf0Ps dtIfR/+8NnQRloLJq9qz4CV+8yDQ6I6WFZpmfyxHzLB355ToGS1IpXOE5o5dxm3CMrD2Erbdu7K VYazC8VEDhHObPt7WhC5iA5lc8fgVXUnSz2Sk+VNC7T8490BuXKqoli1D7G3uEyhfee5eeb1Qtu 8ONqWYto5QkOzXZrlCnKktYsH7J4sqCIXdSzM8FGGvIXn67Jszge3ipuqiMv18aKCseWmttc8uA 8LZH7/+eLl1iZeuTbz13DXk6/2MyXlZH95Z8MCwx8a+8QYGPpX6sRk+i1HJbWdfCLnMQYfc9EMH zRayQIbBXRBjEpvZZ/osPqgjS/XMyt8ZEek4E/BLvnaGM47nTU2/K2crtIYENNBnftlVeTyVlWX WB/tDkwCRVg2JfMDGsGpw== X-Received: by 2002:a05:6000:2511:b0:43c:f3ef:ee36 with SMTP id ffacd0b85a97d-43fe3e0a460mr11869724f8f.33.1776543897650; Sat, 18 Apr 2026 13:24:57 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bd1f:f500:f867:fc8a:5174:5755? ([2a01:4b00:bd1f:f500:f867:fc8a:5174:5755]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e3a7b4sm14602328f8f.22.2026.04.18.13.24.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 Apr 2026 13:24:57 -0700 (PDT) Message-ID: <0a8afc43-dfd8-4aa0-ae94-a82f8c307599@gmail.com> Date: Sat, 18 Apr 2026 21:24:56 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] libbpf: Report error when a negative kprobe offset is specified To: Aaron Tomlin , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260417195816.1265179-1-atomlin@atomlin.com> Content-Language: en-US From: Mykyta Yatsenko In-Reply-To: <20260417195816.1265179-1-atomlin@atomlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/17/26 8:58 PM, Aaron Tomlin wrote: > In attach_kprobe(), the parsing logic uses sscanf() to extract the > target function name and offset from the section definition. Currently, > if a user specifies a negative offset (e.g., SEC("kprobe/func+-100")), > the input is not explicitly caught and reported as an error. > > This commit updates the logic to explicitly notify the user when a > negative integer is provided. To facilitate this check, the offset > variable is changed from unsigned long to long so that sscanf() > can accurately capture a negative input for evaluation. > > If a negative offset is detected, the loader will now print an > informative warning stating that the offset must be non-negative, > and return -EINVAL. > > Additionally, free(func) is called in this new error path to prevent > a memory leak, as the function name string is dynamically allocated > by sscanf(). > > Signed-off-by: Aaron Tomlin > --- you should have used prefix bpf-next and v2 (this is the second version of the patch), you can see how other patches format subjects. The change itself looks correct, the bug is introduced by e3f9bc35ea7e9 ("libbpf: Allow decimal offset for kprobes"). Acked-by: Mykyta Yatsenko > tools/lib/bpf/libbpf.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 42bdba4..cd250fe 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -12271,7 +12271,7 @@ error: > static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf_link **link) > { > DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, opts); > - unsigned long offset = 0; > + long offset = 0; > const char *func_name; > char *func; > int n; > @@ -12293,6 +12293,13 @@ static int attach_kprobe(const struct bpf_program *prog, long cookie, struct bpf > pr_warn("kprobe name is invalid: %s\n", func_name); > return -EINVAL; > } > + > + if (offset < 0) { > + free(func); > + pr_warn("kprobe offset must be a non-negative integer: %li\n", offset); > + return -EINVAL; > + } > + > if (opts.retprobe && offset != 0) { > free(func); > pr_warn("kretprobes do not support offset specification\n");