From: Carlos
sample program to call new bpf helper bpf_get_current_pidns_info.
Signed-off-by: Carlos Neira
---
samples/bpf/Makefile | 3 +++
samples/bpf/trace_ns_info_user.c | 35
samples/bpf/trace_ns_info_user_kern.c | 44
turn 0;
To find out the name PID namespace id of a process, you could use this command:
$ ps -h -o pidns -p
Or this other command:
$ ls -Li /proc//ns/pid
Signed-off-by: Carlos Neira
Carlos Neira (3):
bpf: new helper to obtain namespace data from current task
samples/bpf: added sample co
From: Carlos
Added self-tests for new helper bpf_get_current_pidns_info.
Signed-off-by: Carlos Neira
---
tools/include/uapi/linux/bpf.h | 31 -
tools/testing/selftests/bpf/Makefile | 2 +-
tools/testing/selftests/bpf/bpf_helpers.h | 3
From: Carlos
New bpf helper bpf_get_current_pidns_info.
This helper obtains the active namespace from current and returns
pid, tgid, device and namespace id as seen from that namespace,
allowing to instrument a process inside a container.
Signed-off-by: Carlos Neira
---
fs/internal.h
Currently tests for bpf_get_ns_current_pid_tgid() are outside test_progs.
This change folds test cases into test_progs.
Changes from v11:
- Fixed test failure is not detected.
- Removed EXIT(3) call as it will stop test_progs execution.
Signed-off-by: Carlos Neira
---
tools/testing
Currently tests for bpf_get_ns_current_pid_tgid() are outside test_progs.
This change folds test cases into test_progs.
Changes from V7:
- Rebased changes.
- Changed function scope.
Signed-off-by: Carlos Neira
Acked-by: Andrii Nakryiko
---
tools/testing/selftests/bpf/.gitignore| 1
Currently tests for bpf_get_ns_current_pid_tgid() are outside test_progs.
This change folds test cases into test_progs.
Changes from v8:
- Fixed code style
- Fixed CHECK macro usage
- Removed root namespace sub-test
- Split pid_tgid variable
Signed-off-by: Carlos Neira
---
tools/testing
namespaced test, the new process pid will be 1.
- Used ASSERTEQ on pid/tgid validation.
- Added comment on CLONE(2) call
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 1 -
tools/testing/selftests/bpf/Makefile | 3 +-
.../bpf/prog_tests
Currently tests for bpf_get_ns_current_pid_tgid() are outside test_progs.
This change folds test cases into test_progs.
Changes from v10:
- Code style fixes.
- Remove redundant code.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 1 -
tools/testing
: Carlos Neira
Acked-by: Andrii Nakryiko
---
tools/testing/selftests/bpf/.gitignore| 2 +-
tools/testing/selftests/bpf/Makefile | 2 +-
.../bpf/prog_tests/ns_current_pid_tgid.c | 85 --
.../bpf/prog_tests/ns_current_pidtgid.c | 55 ++
.../bpf/progs
Currently tests for bpf_get_ns_current_pid_tgid() are outside test_progs.
This change folds both tests into test_progs.
Changes from V5:
- Fold both tests into test_progs.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 1 -
tools/testing/selftests/bpf
Currently tests for bpf_get_ns_current_pid_tgid() are outside test_progs.
This change folds test cases into test_progs.
Changes from V6:
- Rebased changes.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 1 -
tools/testing/selftests/bpf/Makefile
This is a series of patches to introduce a new helper called
bpf_get_current_pidns_info, this change has been splitted into the following
patches:
1- Feature introduction
2- Update tools/.../bpf.h
3- Self tests and samples
>From 852a65906122b05b4d1a23af868b2c245d240402 Mon Sep 17 00:00:00 2001
Fr
This is a series of patches to introduce a new helper called
bpf_get_current_pidns_info, this change has been splitted into the following
patches:
1- Feature introduction
2- Update tools/.../bpf.h
3- Self tests and samples
>From b7f5af5c1513b6e89fc5b68ddb1ad65e4fbede02 Mon Sep 17 00:00:00 2001
Fr
>From b7f5af5c1513b6e89fc5b68ddb1ad65e4fbede02 Mon Sep 17 00:00:00 2001
From: Carlos
Date: Mon, 18 Mar 2019 13:09:35 -0300
Subject: [PATCH] [PATCH bpf-next 2/3] BPF: New helper to obtain namespace data
from current task
This helper obtains the active namespace from current and returns pid, tgi
HOSTCFLAGS += -I$(srctree)/tools/lib/
diff --git a/samples/bpf/trace_ns_info_user.c b/samples/bpf/trace_ns_info_user.c
new file mode 100644
index ..e06d08db6f30
--- /dev/null
+++ b/samples/bpf/trace_ns_info_user.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018
onghong in 2017 Linux plumbers
conference.
To address that situation the helper requires inum and dev_t from
/proc/self/ns/pid.
This helper has the same use cases as bpf_get_current_pid_tgid() as it can be
used to do pid filtering even inside a container.
Signed-off-by: Carlos Neira
Carlos Neira
ns_match returns true if the namespace inode and dev_t matches the ones
provided by the caller.
Signed-off-by: Carlos Neira
---
fs/nsfs.c | 8
include/linux/proc_ns.h | 2 ++
2 files changed, 10 insertions(+)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index a0431642c6b5
New bpf helper bpf_get_ns_current_pid_tgid,
This helper will return pid and tgid from current task
which namespace matches dev_t and inode number provided,
this will allows us to instrument a process inside a container.
Signed-off-by: Carlos Neira
---
include/linux/bpf.h | 1 +
include
sync tools/include/uapi/linux/bpf.h to include new helper.
Signed-off-by: Carlos Neira
---
tools/include/uapi/linux/bpf.h | 22 +-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 77c6be96d676
Self tests added for new helper
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/bpf_helpers.h | 4 +
.../bpf/prog_tests/get_ns_current_pid_tgid.c | 85 +++
.../bpf/progs/get_ns_current_pid_tgid_kern.c | 53
3 files changed, 142 insertions
selftests
- refactored ebpf helper
Signed-off-by: Carlos Neira
Carlos Neira (5):
fs/nsfs.c: added ns_match
bpf: added new helper bpf_get_ns_current_pid_tgid
tools: Added bpf_get_ns_current_pid_tgid helper
tools/testing/selftests/bpf: Add self-tests for new helper.
bpf_helpers_doc.py:
ns_match returns true if the namespace inode and dev_t matches the ones
provided by the caller.
Signed-off-by: Carlos Neira
---
fs/nsfs.c | 8
include/linux/proc_ns.h | 2 ++
2 files changed, 10 insertions(+)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index a0431642c6b5
New bpf helper bpf_get_ns_current_pid_tgid,
This helper will return pid and tgid from current task
which namespace matches dev_t and inode number provided,
this will allows us to instrument a process inside a container.
Signed-off-by: Carlos Neira
---
include/linux/bpf.h | 1 +
include
sync tools/include/uapi/linux/bpf.h to include new helper.
Signed-off-by: Carlos Neira
---
tools/include/uapi/linux/bpf.h | 20 +++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index a65c3b0c6935
Self tests added for new helper
Signed-off-by: Carlos Neira
---
.../bpf/prog_tests/get_ns_current_pid_tgid.c | 96 +++
.../bpf/progs/get_ns_current_pid_tgid_kern.c | 53 ++
2 files changed, 149 insertions(+)
create mode 100644
tools/testing/selftests/bpf/prog_tests
Add struct bpf_pidns_info to known types
Signed-off-by: Carlos Neira
---
scripts/bpf_helpers_doc.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/scripts/bpf_helpers_doc.py b/scripts/bpf_helpers_doc.py
index 7df9ce598ff9..d42eb185810f 100755
--- a/scripts/bpf_helpers_doc.py
+++ b/scripts
Self tests added for new helper
Signed-off-by: Carlos Neira
---
.../bpf/prog_tests/ns_current_pid_tgid.c | 87 +++
.../bpf/progs/test_ns_current_pid_tgid.c | 37
2 files changed, 124 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests
Add struct bpf_pidns_info to known types
Signed-off-by: Carlos Neira
---
scripts/bpf_helpers_doc.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/scripts/bpf_helpers_doc.py b/scripts/bpf_helpers_doc.py
index 7548569e8076..021cc387d414 100755
--- a/scripts/bpf_helpers_doc.py
+++ b/scripts
New bpf helper bpf_get_ns_current_pid_tgid,
This helper will return pid and tgid from current task
which namespace matches dev_t and inode number provided,
this will allows us to instrument a process inside a container.
Signed-off-by: Carlos Neira
---
include/linux/bpf.h | 1 +
include
ns_match returns true if the namespace inode and dev_t matches the ones
provided by the caller.
Signed-off-by: Carlos Neira
---
fs/nsfs.c | 14 ++
include/linux/proc_ns.h | 2 ++
2 files changed, 16 insertions(+)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index a0431642c6b5
selftests
- refactored ebpf helper
Signed-off-by: Carlos Neira
Carlos Neira (5):
fs/nsfs.c: added ns_match
bpf: added new helper bpf_get_ns_current_pid_tgid
tools: Added bpf_get_ns_current_pid_tgid helper
tools/testing/selftests/bpf: Add self-tests for new helper.
bpf_helpers_doc.py:
sync tools/include/uapi/linux/bpf.h to include new helper.
Signed-off-by: Carlos Neira
---
tools/include/uapi/linux/bpf.h | 20 +++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 4af8b0819a32
a standalone test.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 2 +-
tools/testing/selftests/bpf/Makefile | 3 +-
.../bpf/prog_tests/ns_current_pid_tgid.c | 85 -
.../bpf/prog_tests/ns_current_pidtgid.c | 59
.
- Removed unnecessary dependency on Makefile
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 2 +-
tools/testing/selftests/bpf/Makefile | 4 +-
.../bpf/prog_tests/ns_current_pid_tgid.c | 85 --
.../bpf/prog_tests/ns_current_pidtgid.c | 54
Changes from V2:
- Test not creating a new namespace has been included in test_progs.
- Test creating a new pid namespace has been added as a standalone test.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 2 +-
tools/testing/selftests/bpf/Makefile
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/.gitignore| 2 +-
tools/testing/selftests/bpf/Makefile | 3 +-
.../bpf/prog_tests/ns_current_pid_tgid.c | 85 -
.../bpf/prog_tests/ns_current_pidtgid.c | 59
.../bpf/progs
ned-off-by: Carlos Neira
---
include/linux/bpf.h | 1 +
include/uapi/linux/bpf.h | 15 -
kernel/bpf/core.c | 1 +
kernel/bpf/helpers.c | 28 +
kernel/trace/bpf_trace.c
folds tests from test_current_pid_tgid_new_ns into test_progs.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/Makefile | 3 +-
.../bpf/prog_tests/ns_current_pid_tgid.c | 112 +++-
.../bpf/test_current_pid_tgid_new_ns.c| 159 --
3
folds tests from test_current_pid_tgid_new_ns into test_progs.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/Makefile | 3 +-
.../bpf/prog_tests/ns_current_pid_tgid.c | 112 +++-
.../bpf/test_current_pid_tgid_new_ns.c| 159 --
3
folds tests from test_current_pid_tgid_new_ns into test_progs.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/Makefile | 3 +-
.../bpf/prog_tests/ns_current_pid_tgid.c | 112 +++-
.../bpf/test_current_pid_tgid_new_ns.c| 159 --
3
Signed-off-by: Carlos Neira
---
fs/internal.h | 2 --
fs/namei.c| 1 -
include/linux/namei.h | 4
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/fs/internal.h b/fs/internal.h
index 315fcd8d237c..6647e15dd419 100644
--- a/fs/internal.h
+++ b/fs/internal.h
This helper(bpf_get_current_pidns_info) obtains the active namespace from
current and returns pid, tgid, device and namespace id as seen from that
namespace, allowing to instrument a process inside a container.
Signed-off-by: Carlos Neira
---
include/linux/bpf.h | 1 +
include/uapi/linux
Added 2 selftest:
bpf_get_current_pidns_info helper is called in an interrupt
context and also in a non interrupt context.
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/Makefile | 2 +-
tools/testing/selftests/bpf/bpf_helpers.h | 3 +
.../testing
Signed-off-by: Carlos Neira
---
tools/include/uapi/linux/bpf.h | 35 ++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index b5889257cc33..3ec9aa1438b7 100644
--- a/tools/include/uapi
ext.
Code style fixes.
Added more comments on bpf helper struct member.
Signed-off-by: Carlos Neira
Carlos Neira (4):
fs/namei.c: make available filename_lookup() for bpf helpers.
bpf: new helper to obtain namespace data from current task New bpf
helper bpf_get_current_pidns_info.
tools:
onghong in 2017 Linux plumbers
conference.
To address that situation the helper requires inum and dev_t from
/proc/self/ns/pid.
This helper has the same use cases as bpf_get_current_pid_tgid() as it can be
used to do pid filtering even inside a container.
Signed-off-by: Carlos Neira
Carlos Neira
ns_match returns true if the namespace inode and dev_t matches the ones
provided by the caller.
Signed-off-by: Carlos Neira
---
fs/nsfs.c | 8
include/linux/proc_ns.h | 2 ++
2 files changed, 10 insertions(+)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index a0431642c6b5
Signed-off-by: Carlos Neira
---
tools/include/uapi/linux/bpf.h | 18 +-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 77c6be96d676..9272dc8fb08c 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b
New bpf helper bpf_get_ns_current_pid_tgid,
This helper will return pid and tgid from current task
which namespace matches dev_t and inode number provided,
this will allows us to instrument a process inside a container.
Signed-off-by: Carlos Neira
---
include/linux/bpf.h | 1 +
include
Self tests added for new helper
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/Makefile | 2 +-
tools/testing/selftests/bpf/bpf_helpers.h | 3 +
.../selftests/bpf/progs/test_pidns_kern.c | 71
tools/testing/selftests/bpf/test_pidns.c | 152
ns_match returns true if the namespace inode and dev_t matches the ones
provided by the caller.
Signed-off-by: Carlos Neira
---
fs/nsfs.c | 8
include/linux/proc_ns.h | 2 ++
2 files changed, 10 insertions(+)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index a0431642c6b5
Self tests added for new helper
Signed-off-by: Carlos Neira
---
tools/testing/selftests/bpf/bpf_helpers.h | 3 +
.../bpf/prog_tests/get_ns_current_pid_tgid.c | 85 +++
.../bpf/progs/get_ns_current_pid_tgid_kern.c | 47 ++
3 files changed, 135 insertions(+)
create
New bpf helper bpf_get_ns_current_pid_tgid,
This helper will return pid and tgid from current task
which namespace matches dev_t and inode number provided,
this will allows us to instrument a process inside a container.
Signed-off-by: Carlos Neira
---
include/linux/bpf.h | 1 +
include
d dev from u32 to u64.
- Moved self-test to test_progs.
- Remove unneeded maps in self-test.
Signed-off-by: Carlos Neira
Carlos Neira (4):
fs/nsfs.c: added ns_match
bpf: added new helper bpf_get_ns_current_pid_tgid
tools: Added bpf_get_ns_current_pid_tgid helper
tools/testing/selftests/bpf
sync tools/include/uapi/linux/bpf.h to include new helper.
Signed-off-by: Carlos Neira
---
tools/include/uapi/linux/bpf.h | 18 +-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 77c6be96d676
o_user.c b/samples/bpf/trace_ns_info_user.c
new file mode 100644
index ..e06d08db6f30
--- /dev/null
+++ b/samples/bpf/trace_ns_info_user.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018 Carlos Neira cneirabus...@gmail.com
+ *
+ * This program is free softwar
Yes, you are right. I'll resubmit the patch with those corrections.
Thanks a lot for catching this.
Thu, Aug 09, 2018 at 03:46:53PM +0200, Jesper Dangaard Brouer wrote:
> On Thu, 9 Aug 2018 09:18:00 -0400
> Carlos Neira wrote:
>
> > From: cneira
> >
> >
Jesper,
Here is the updated patch.
>From 92633f6819423093932e8d04aa3dc99a5913f6fd Mon Sep 17 00:00:00 2001
From: Carlos Neira
Date: Thu, 9 Aug 2018 09:55:32 -0400
Subject: [PATCH bpf-next] BPF: helpers: New helper to obtain namespace
data from current task
This helper obtains the act
o_user.c b/samples/bpf/trace_ns_info_user.c
new file mode 100644
index ..e06d08db6f30
--- /dev/null
+++ b/samples/bpf/trace_ns_info_user.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2018 Carlos Neira cneirabus...@gmail.com
+ *
+ * This program is free software; y
Jesper,
I'm sorry, thanks a lot for the pointers to the current process.
I just submitted v2 of for this patch. Thanks again for checking this out.
Bests
On Fri, Aug 10, 2018 at 12:40:29PM +0200, Jesper Dangaard Brouer wrote:
> On Thu, 9 Aug 2018 12:07:00 -0400
> Carlos N
61 matches
Mail list logo