]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf, xdp: constify some bpf_prog * function arguments
authorAlexander Lobakin <aleksander.lobakin@intel.com>
Tue, 3 Dec 2024 17:37:25 +0000 (18:37 +0100)
committerJakub Kicinski <kuba@kernel.org>
Fri, 6 Dec 2024 02:41:06 +0000 (18:41 -0800)
In lots of places, bpf_prog pointer is used only for tracing or other
stuff that doesn't modify the structure itself. Same for net_device.
Address at least some of them and add `const` attributes there. The
object code didn't change, but that may prevent unwanted data
modifications and also allow more helpers to have const arguments.

Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/bpf.h
include/linux/filter.h
include/linux/netdevice.h
include/linux/skbuff.h
kernel/bpf/devmap.c
net/core/dev.c
net/core/filter.c
net/core/skbuff.c

index eaee2a819f4c150a34a7b1075584711609682e4c..ec3acb16359e56524156d3d33c089fd858e77622 100644 (file)
@@ -2591,10 +2591,10 @@ int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_frame *xdpf,
 int dev_map_enqueue_multi(struct xdp_frame *xdpf, struct net_device *dev_rx,
                          struct bpf_map *map, bool exclude_ingress);
 int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,
-                            struct bpf_prog *xdp_prog);
+                            const struct bpf_prog *xdp_prog);
 int dev_map_redirect_multi(struct net_device *dev, struct sk_buff *skb,
-                          struct bpf_prog *xdp_prog, struct bpf_map *map,
-                          bool exclude_ingress);
+                          const struct bpf_prog *xdp_prog,
+                          struct bpf_map *map, bool exclude_ingress);
 
 void __cpu_map_flush(struct list_head *flush_list);
 int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *xdpf,
@@ -2864,15 +2864,15 @@ struct sk_buff;
 
 static inline int dev_map_generic_redirect(struct bpf_dtab_netdev *dst,
                                           struct sk_buff *skb,
-                                          struct bpf_prog *xdp_prog)
+                                          const struct bpf_prog *xdp_prog)
 {
        return 0;
 }
 
 static inline
 int dev_map_redirect_multi(struct net_device *dev, struct sk_buff *skb,
-                          struct bpf_prog *xdp_prog, struct bpf_map *map,
-                          bool exclude_ingress)
+                          const struct bpf_prog *xdp_prog,
+                          struct bpf_map *map, bool exclude_ingress)
 {
        return 0;
 }
index 3a21947f2fd441b6e91a80eae121d5b37cf3c68b..9a5d23ae3855749427173e7102c68abce7389ac8 100644 (file)
@@ -1179,17 +1179,18 @@ static inline int xdp_ok_fwd_dev(const struct net_device *fwd,
  * This does not appear to be a real limitation for existing software.
  */
 int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
-                           struct xdp_buff *xdp, struct bpf_prog *prog);
+                           struct xdp_buff *xdp, const struct bpf_prog *prog);
 int xdp_do_redirect(struct net_device *dev,
                    struct xdp_buff *xdp,
-                   struct bpf_prog *prog);
+                   const struct bpf_prog *prog);
 int xdp_do_redirect_frame(struct net_device *dev,
                          struct xdp_buff *xdp,
                          struct xdp_frame *xdpf,
-                         struct bpf_prog *prog);
+                         const struct bpf_prog *prog);
 void xdp_do_flush(void);
 
-void bpf_warn_invalid_xdp_action(struct net_device *dev, struct bpf_prog *prog, u32 act);
+void bpf_warn_invalid_xdp_action(const struct net_device *dev,
+                                const struct bpf_prog *prog, u32 act);
 
 #ifdef CONFIG_INET
 struct sock *bpf_run_sk_reuseport(struct sock_reuseport *reuse, struct sock *sk,
index ecc686409161ea8684926434a9dcb233e065dd6c..ecca21387a6838fbe37989b5f825d0a9338ae2ba 100644 (file)
@@ -3958,9 +3958,9 @@ static inline void dev_consume_skb_any(struct sk_buff *skb)
 }
 
 u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
-                            struct bpf_prog *xdp_prog);
-void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog);
-int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff **pskb);
+                            const struct bpf_prog *xdp_prog);
+void generic_xdp_tx(struct sk_buff *skb, const struct bpf_prog *xdp_prog);
+int do_xdp_generic(const struct bpf_prog *xdp_prog, struct sk_buff **pskb);
 int netif_rx(struct sk_buff *skb);
 int __netif_rx(struct sk_buff *skb);
 
index 58009fa661026bd9a9a1448cc7fdaea29b4901ef..95452d1a07fcfe300caf466500db75d58a34a0fe 100644 (file)
@@ -3627,7 +3627,7 @@ static inline netmem_ref skb_frag_netmem(const skb_frag_t *frag)
 int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb,
                    unsigned int headroom);
 int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb,
-                        struct bpf_prog *prog);
+                        const struct bpf_prog *prog);
 
 /**
  * skb_frag_address - gets the address of the data contained in a paged fragment
index 7878be18e9d264d97b8e99b5a0847616174046de..effde52bc857fa170c6bdea8f6a370a35ed967ca 100644 (file)
@@ -678,7 +678,7 @@ int dev_map_enqueue_multi(struct xdp_frame *xdpf, struct net_device *dev_rx,
 }
 
 int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,
-                            struct bpf_prog *xdp_prog)
+                            const struct bpf_prog *xdp_prog)
 {
        int err;
 
@@ -701,7 +701,7 @@ int dev_map_generic_redirect(struct bpf_dtab_netdev *dst, struct sk_buff *skb,
 
 static int dev_map_redirect_clone(struct bpf_dtab_netdev *dst,
                                  struct sk_buff *skb,
-                                 struct bpf_prog *xdp_prog)
+                                 const struct bpf_prog *xdp_prog)
 {
        struct sk_buff *nskb;
        int err;
@@ -720,8 +720,8 @@ static int dev_map_redirect_clone(struct bpf_dtab_netdev *dst,
 }
 
 int dev_map_redirect_multi(struct net_device *dev, struct sk_buff *skb,
-                          struct bpf_prog *xdp_prog, struct bpf_map *map,
-                          bool exclude_ingress)
+                          const struct bpf_prog *xdp_prog,
+                          struct bpf_map *map, bool exclude_ingress)
 {
        struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);
        struct bpf_dtab_netdev *dst, *last_dst = NULL;
index 45a8c3dd4a64839c403dec5e3f763dfa2f591415..40a2332e3fa027faeaff6888674d645b5210fb72 100644 (file)
@@ -4931,7 +4931,7 @@ static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb)
 }
 
 u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
-                            struct bpf_prog *xdp_prog)
+                            const struct bpf_prog *xdp_prog)
 {
        void *orig_data, *orig_data_end, *hard_start;
        struct netdev_rx_queue *rxqueue;
@@ -5033,7 +5033,7 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
 }
 
 static int
-netif_skb_check_for_xdp(struct sk_buff **pskb, struct bpf_prog *prog)
+netif_skb_check_for_xdp(struct sk_buff **pskb, const struct bpf_prog *prog)
 {
        struct sk_buff *skb = *pskb;
        int err, hroom, troom;
@@ -5057,7 +5057,7 @@ netif_skb_check_for_xdp(struct sk_buff **pskb, struct bpf_prog *prog)
 
 static u32 netif_receive_generic_xdp(struct sk_buff **pskb,
                                     struct xdp_buff *xdp,
-                                    struct bpf_prog *xdp_prog)
+                                    const struct bpf_prog *xdp_prog)
 {
        struct sk_buff *skb = *pskb;
        u32 mac_len, act = XDP_DROP;
@@ -5110,7 +5110,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff **pskb,
  * and DDOS attacks will be more effective. In-driver-XDP use dedicated TX
  * queues, so they do not have this starvation issue.
  */
-void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog)
+void generic_xdp_tx(struct sk_buff *skb, const struct bpf_prog *xdp_prog)
 {
        struct net_device *dev = skb->dev;
        struct netdev_queue *txq;
@@ -5135,7 +5135,7 @@ void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog)
 
 static DEFINE_STATIC_KEY_FALSE(generic_xdp_needed_key);
 
-int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff **pskb)
+int do_xdp_generic(const struct bpf_prog *xdp_prog, struct sk_buff **pskb)
 {
        struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;
 
index 6625b3f563a4a3110a76b9c12a46340828e16b6e..fac245065b0a433f913a2de9b7c3bf76e2fe1696 100644 (file)
@@ -4348,9 +4348,9 @@ u32 xdp_master_redirect(struct xdp_buff *xdp)
 EXPORT_SYMBOL_GPL(xdp_master_redirect);
 
 static inline int __xdp_do_redirect_xsk(struct bpf_redirect_info *ri,
-                                       struct net_device *dev,
+                                       const struct net_device *dev,
                                        struct xdp_buff *xdp,
-                                       struct bpf_prog *xdp_prog)
+                                       const struct bpf_prog *xdp_prog)
 {
        enum bpf_map_type map_type = ri->map_type;
        void *fwd = ri->tgt_value;
@@ -4371,10 +4371,10 @@ err:
        return err;
 }
 
-static __always_inline int __xdp_do_redirect_frame(struct bpf_redirect_info *ri,
-                                                  struct net_device *dev,
-                                                  struct xdp_frame *xdpf,
-                                                  struct bpf_prog *xdp_prog)
+static __always_inline int
+__xdp_do_redirect_frame(struct bpf_redirect_info *ri, struct net_device *dev,
+                       struct xdp_frame *xdpf,
+                       const struct bpf_prog *xdp_prog)
 {
        enum bpf_map_type map_type = ri->map_type;
        void *fwd = ri->tgt_value;
@@ -4443,7 +4443,7 @@ err:
 }
 
 int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
-                   struct bpf_prog *xdp_prog)
+                   const struct bpf_prog *xdp_prog)
 {
        struct bpf_redirect_info *ri = bpf_net_ctx_get_ri();
        enum bpf_map_type map_type = ri->map_type;
@@ -4457,7 +4457,8 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
 EXPORT_SYMBOL_GPL(xdp_do_redirect);
 
 int xdp_do_redirect_frame(struct net_device *dev, struct xdp_buff *xdp,
-                         struct xdp_frame *xdpf, struct bpf_prog *xdp_prog)
+                         struct xdp_frame *xdpf,
+                         const struct bpf_prog *xdp_prog)
 {
        struct bpf_redirect_info *ri = bpf_net_ctx_get_ri();
        enum bpf_map_type map_type = ri->map_type;
@@ -4472,9 +4473,9 @@ EXPORT_SYMBOL_GPL(xdp_do_redirect_frame);
 static int xdp_do_generic_redirect_map(struct net_device *dev,
                                       struct sk_buff *skb,
                                       struct xdp_buff *xdp,
-                                      struct bpf_prog *xdp_prog, void *fwd,
-                                      enum bpf_map_type map_type, u32 map_id,
-                                      u32 flags)
+                                      const struct bpf_prog *xdp_prog,
+                                      void *fwd, enum bpf_map_type map_type,
+                                      u32 map_id, u32 flags)
 {
        struct bpf_redirect_info *ri = bpf_net_ctx_get_ri();
        struct bpf_map *map;
@@ -4528,7 +4529,8 @@ err:
 }
 
 int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,
-                           struct xdp_buff *xdp, struct bpf_prog *xdp_prog)
+                           struct xdp_buff *xdp,
+                           const struct bpf_prog *xdp_prog)
 {
        struct bpf_redirect_info *ri = bpf_net_ctx_get_ri();
        enum bpf_map_type map_type = ri->map_type;
@@ -9075,7 +9077,8 @@ static bool xdp_is_valid_access(int off, int size,
        return __is_valid_xdp_access(off, size);
 }
 
-void bpf_warn_invalid_xdp_action(struct net_device *dev, struct bpf_prog *prog, u32 act)
+void bpf_warn_invalid_xdp_action(const struct net_device *dev,
+                                const struct bpf_prog *prog, u32 act)
 {
        const u32 act_max = XDP_REDIRECT;
 
index 6841e61a6bd0b66e7b1df0545697604479c6b7a1..a441613a1e6c1765f7fc2e40f982b81f8f8fdb96 100644 (file)
@@ -1009,7 +1009,7 @@ int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb,
 EXPORT_SYMBOL(skb_pp_cow_data);
 
 int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb,
-                        struct bpf_prog *prog)
+                        const struct bpf_prog *prog)
 {
        if (!prog->aux->xdp_has_frags)
                return -EINVAL;