From patchwork Wed Dec 13 14:12:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 13491082 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D1F1F2E631 for ; Wed, 13 Dec 2023 14:12:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t9lpHijB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2F8EC433C7; Wed, 13 Dec 2023 14:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702476760; bh=ecipoyNjahWNdMuCOVl84PSVApDNIhiU9gCXxwvwFtk=; h=From:To:Cc:Subject:Date:From; b=t9lpHijBS6YLNxgqwXK5TFmoCTMysFQDmJLP2n73Vs+AN0rzLOvHk5kIzQ+U7eZ2s P3El3mktFXOLLyFUxgJe5i6/411xe581/jYzfy0qCzVlA/rbJcesXZh16vQ5IGOKOa 5rFcQKByVBMm7URO4o9JvtZCLLirEvGeGE29qZly9MZ8bOAQwgJ3EhOecv5FvkfrDp GnHTwXrNiXSH83b2oLjHfkwcSTq4TV7BPYyU88yk82T2sOxuoQmxLnqVhcK3SVZT1u E0+6r+rQrt3JpbKyYuqba0HdMMVjISCUz3C8XppB8oYm0whhk5bj2MRBcPgMejCCPQ d8nBZfJerVEqA== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Oleg Nesterov Subject: [RFC bpf-next 1/2] bpf: Fail uprobe multi link with negative offset Date: Wed, 13 Dec 2023 15:12:33 +0100 Message-ID: <20231213141234.1210389-1-jolsa@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Currently the __uprobe_register will return 0 (success) when called with negative offset. The reason is that the call to register_for_each_vma and then build_map_info won't return error for negative offset. They just won't do anything - no matching vma is found so there's no registered breakpoint for the uprobe. I don't think we can change the behaviour of __uprobe_register and fail for negative uprobe offset, because apps might depend on that already. But I think we can still make the change and check for it on bpf multi link syscall level. Signed-off-by: Jiri Olsa Reviewed-by: Alan Maguire --- kernel/trace/bpf_trace.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 774cf476a892..0dbf8d9b3ace 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3397,6 +3397,11 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr goto error_free; } + if (uprobes[i].offset < 0) { + err = -EINVAL; + goto error_free; + } + uprobes[i].link = link; if (flags & BPF_F_UPROBE_MULTI_RETURN)