eBPF-based security platform
upatch: drop the XDP link's namespace check that checked nothing
John Fastabendd6af2d37725e
diff --git a/Documentation/upatches/write/attach-kinds.rst b/Documentation/upatches/write/attach-kinds.rstindex 6e747bae..2c5cf546 100644--- a/Documentation/upatches/write/attach-kinds.rst+++ b/Documentation/upatches/write/attach-kinds.rst@@ -333,9 +333,11 @@ only warned about before the reboot. A setting root makes after boot is the recowhich leaves the device unattached, warns, and lets ``status`` list it. Existing XDPprograms are never replaced. Device classification and peer identityare rechecked around attachment, and the returned link's ifindex is-checked before pinning. A link on another device or outside the initial-namespace is ``attach_scope_mismatch`` and fails the load, the restore-or the reconcile pass, never a skipped device.+checked before pinning. A link the kernel reports on another device is+``attach_scope_mismatch`` and fails the load, the restore or the+reconcile pass, never a skipped device. The link reports no namespace:+the load checks its own before it reads the devices, and a run outside+the initial namespace fails as ``attach_scope_mismatch`` too.Every XDP program is loaded with ``BPF_F_XDP_HAS_FRAGS``, so it can run ona device whose MTU does not fit one buffer. A selected device with nativediff --git a/builtin-upatch.c b/builtin-upatch.cindex 8fb08a60..d5b721d0 100644--- a/builtin-upatch.c+++ b/builtin-upatch.c@@ -1236,7 +1236,8 @@ static int link_matches_spec(int link_fd,if (info.type != BPF_LINK_TYPE_XDP || !ifindex ||info.xdp.ifindex != ifindex)return -EXDEV;- return netns_initial();+ /* The caller's namespace was checked before the devices were read. */+ return 0;case UPATCH_ATTACH_CGROUP_SKB_INGRESS:case UPATCH_ATTACH_CGROUP_SKB_EGRESS:return -EXDEV;diff --git a/testing/unit/xdp.c b/testing/unit/xdp.cindex a88965e3..a26c03ae 100644--- a/testing/unit/xdp.c+++ b/testing/unit/xdp.c@@ -194,7 +194,7 @@ static void only_a_device_without_xdp_lacks_it(void)EXPECT_STREQ(xdp_attach_strerror(XDP_ERR_DRIVER_SETTINGS),"the driver refuses XDP in its current settings");EXPECT_STREQ(xdp_attach_strerror(XDP_ERR_LINK_SCOPE),- "the link is not on the device and namespace it was made for");+ "the link is not on the device it was made for");}static void a_driver_refusal_is_told_from_other_errors(void)diff --git a/util/xdp.c b/util/xdp.cindex 0be7dc0b..aafb0e98 100644--- a/util/xdp.c+++ b/util/xdp.c@@ -554,7 +554,7 @@ const char *xdp_attach_strerror(int err)case XDP_ERR_OCCUPIED:return "the device runs another XDP program";case XDP_ERR_LINK_SCOPE:- return "the link is not on the device and namespace it was made for";+ return "the link is not on the device it was made for";default:return strerror(-err);}diff --git a/util/xdp.h b/util/xdp.hindex f61b376d..d40e5dbd 100644--- a/util/xdp.h+++ b/util/xdp.h@@ -25,7 +25,7 @@ enum xdp_attach_err {XDP_ERR_DRIVER_SETTINGS,/* The device runs another XDP program: the link create says so. */XDP_ERR_OCCUPIED,- /* The kernel made the link for another device or namespace. */+ /* The kernel made the link for another device. */XDP_ERR_LINK_SCOPE,};