Skip to content

Commit a685d0d

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf-next 2023-06-23 We've added 49 non-merge commits during the last 24 day(s) which contain a total of 70 files changed, 1935 insertions(+), 442 deletions(-). The main changes are: 1) Extend bpf_fib_lookup helper to allow passing the route table ID, from Louis DeLosSantos. 2) Fix regsafe() in verifier to call check_ids() for scalar registers, from Eduard Zingerman. 3) Extend the set of cpumask kfuncs with bpf_cpumask_first_and() and a rework of bpf_cpumask_any*() kfuncs. Additionally, add selftests, from David Vernet. 4) Fix socket lookup BPF helpers for tc/XDP to respect VRF bindings, from Gilad Sever. 5) Change bpf_link_put() to use workqueue unconditionally to fix it under PREEMPT_RT, from Sebastian Andrzej Siewior. 6) Follow-ups to address issues in the bpf_refcount shared ownership implementation, from Dave Marchevsky. 7) A few general refactorings to BPF map and program creation permissions checks which were part of the BPF token series, from Andrii Nakryiko. 8) Various fixes for benchmark framework and add a new benchmark for BPF memory allocator to BPF selftests, from Hou Tao. 9) Documentation improvements around iterators and trusted pointers, from Anton Protopopov. 10) Small cleanup in verifier to improve allocated object check, from Daniel T. Lee. 11) Improve performance of bpf_xdp_pointer() by avoiding access to shared_info when XDP packet does not have frags, from Jesper Dangaard Brouer. 12) Silence a harmless syzbot-reported warning in btf_type_id_size(), from Yonghong Song. 13) Remove duplicate bpfilter_umh_cleanup in favor of umd_cleanup_helper, from Jarkko Sakkinen. 14) Fix BPF selftests build for resolve_btfids under custom HOSTCFLAGS, from Viktor Malik. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (49 commits) bpf, docs: Document existing macros instead of deprecated bpf, docs: BPF Iterator Document selftests/bpf: Fix compilation failure for prog vrf_socket_lookup selftests/bpf: Add vrf_socket_lookup tests bpf: Fix bpf socket lookup from tc/xdp to respect socket VRF bindings bpf: Call __bpf_sk_lookup()/__bpf_skc_lookup() directly via TC hookpoint bpf: Factor out socket lookup functions for the TC hookpoint. selftests/bpf: Set the default value of consumer_cnt as 0 selftests/bpf: Ensure that next_cpu() returns a valid CPU number selftests/bpf: Output the correct error code for pthread APIs selftests/bpf: Use producer_cnt to allocate local counter array xsk: Remove unused inline function xsk_buff_discard() bpf: Keep BPF_PROG_LOAD permission checks clear of validations bpf: Centralize permissions checks for all BPF map types bpf: Inline map creation logic in map_create() function bpf: Move unprivileged checks into map_create() and bpf_prog_load() bpf: Remove in_atomic() from bpf_link_put(). selftests/bpf: Verify that check_ids() is used for scalars in regsafe() bpf: Verify scalar ids mapping in regsafe() using check_ids() selftests/bpf: Check if mark_chain_precision() follows scalar ids ... ==================== Link: https://lore.kernel.org/r/20230623211256.8409-1-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents d1d29a4 + fbc5669 commit a685d0d

70 files changed

Lines changed: 1935 additions & 442 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/bpf/bpf_iterators.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,8 @@ The following is the breakdown for each field in struct ``bpf_iter_reg``.
238238
that the kernel function cond_resched() is called to avoid other kernel
239239
subsystem (e.g., rcu) misbehaving.
240240
* - seq_info
241-
- Specifies certain action requests in the kernel BPF iterator
242-
infrastructure. Currently, only BPF_ITER_RESCHED is supported. This means
243-
that the kernel function cond_resched() is called to avoid other kernel
244-
subsystem (e.g., rcu) misbehaving.
245-
241+
- Specifies the set of seq operations for the BPF iterator and helpers to
242+
initialize/free the private data for the corresponding ``seq_file``.
246243

247244
`Click here
248245
<https://lore.kernel.org/bpf/20210212183107.50963-2-songliubraving@fb.com/>`_

Documentation/bpf/cpumasks.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,15 @@ In addition to the above kfuncs, there is also a set of read-only kfuncs that
351351
can be used to query the contents of cpumasks.
352352

353353
.. kernel-doc:: kernel/bpf/cpumask.c
354-
:identifiers: bpf_cpumask_first bpf_cpumask_first_zero bpf_cpumask_test_cpu
354+
:identifiers: bpf_cpumask_first bpf_cpumask_first_zero bpf_cpumask_first_and
355+
bpf_cpumask_test_cpu
355356

356357
.. kernel-doc:: kernel/bpf/cpumask.c
357358
:identifiers: bpf_cpumask_equal bpf_cpumask_intersects bpf_cpumask_subset
358359
bpf_cpumask_empty bpf_cpumask_full
359360

360361
.. kernel-doc:: kernel/bpf/cpumask.c
361-
:identifiers: bpf_cpumask_any bpf_cpumask_any_and
362+
:identifiers: bpf_cpumask_any_distribute bpf_cpumask_any_and_distribute
362363

363364
----
364365

Documentation/bpf/kfuncs.rst

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,23 +227,49 @@ absolutely no ABI stability guarantees.
227227

228228
As mentioned above, a nested pointer obtained from walking a trusted pointer is
229229
no longer trusted, with one exception. If a struct type has a field that is
230-
guaranteed to be valid as long as its parent pointer is trusted, the
231-
``BTF_TYPE_SAFE_NESTED`` macro can be used to express that to the verifier as
232-
follows:
230+
guaranteed to be valid (trusted or rcu, as in KF_RCU description below) as long
231+
as its parent pointer is valid, the following macros can be used to express
232+
that to the verifier:
233+
234+
* ``BTF_TYPE_SAFE_TRUSTED``
235+
* ``BTF_TYPE_SAFE_RCU``
236+
* ``BTF_TYPE_SAFE_RCU_OR_NULL``
237+
238+
For example,
239+
240+
.. code-block:: c
241+
242+
BTF_TYPE_SAFE_TRUSTED(struct socket) {
243+
struct sock *sk;
244+
};
245+
246+
or
233247

234248
.. code-block:: c
235249
236-
BTF_TYPE_SAFE_NESTED(struct task_struct) {
250+
BTF_TYPE_SAFE_RCU(struct task_struct) {
237251
const cpumask_t *cpus_ptr;
252+
struct css_set __rcu *cgroups;
253+
struct task_struct __rcu *real_parent;
254+
struct task_struct *group_leader;
238255
};
239256
240257
In other words, you must:
241258

242-
1. Wrap the trusted pointer type in the ``BTF_TYPE_SAFE_NESTED`` macro.
259+
1. Wrap the valid pointer type in a ``BTF_TYPE_SAFE_*`` macro.
243260

244-
2. Specify the type and name of the trusted nested field. This field must match
261+
2. Specify the type and name of the valid nested field. This field must match
245262
the field in the original type definition exactly.
246263

264+
A new type declared by a ``BTF_TYPE_SAFE_*`` macro also needs to be emitted so
265+
that it appears in BTF. For example, ``BTF_TYPE_SAFE_TRUSTED(struct socket)``
266+
is emitted in the ``type_is_trusted()`` function as follows:
267+
268+
.. code-block:: c
269+
270+
BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct socket));
271+
272+
247273
2.4.5 KF_SLEEPABLE flag
248274
-----------------------
249275

include/linux/bpf_verifier.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,6 @@ struct bpf_idx_pair {
313313
u32 idx;
314314
};
315315

316-
struct bpf_id_pair {
317-
u32 old;
318-
u32 cur;
319-
};
320-
321316
#define MAX_CALL_FRAMES 8
322317
/* Maximum number of register states that can exist at once */
323318
#define BPF_ID_MAP_SIZE ((MAX_BPF_REG + MAX_BPF_STACK / BPF_REG_SIZE) * MAX_CALL_FRAMES)
@@ -557,6 +552,21 @@ struct backtrack_state {
557552
u64 stack_masks[MAX_CALL_FRAMES];
558553
};
559554

555+
struct bpf_id_pair {
556+
u32 old;
557+
u32 cur;
558+
};
559+
560+
struct bpf_idmap {
561+
u32 tmp_id_gen;
562+
struct bpf_id_pair map[BPF_ID_MAP_SIZE];
563+
};
564+
565+
struct bpf_idset {
566+
u32 count;
567+
u32 ids[BPF_ID_MAP_SIZE];
568+
};
569+
560570
/* single container for all structs
561571
* one verifier_env per bpf_check() call
562572
*/
@@ -588,7 +598,10 @@ struct bpf_verifier_env {
588598
const struct bpf_line_info *prev_linfo;
589599
struct bpf_verifier_log log;
590600
struct bpf_subprog_info subprog_info[BPF_MAX_SUBPROGS + 1];
591-
struct bpf_id_pair idmap_scratch[BPF_ID_MAP_SIZE];
601+
union {
602+
struct bpf_idmap idmap_scratch;
603+
struct bpf_idset idset_scratch;
604+
};
592605
struct {
593606
int *insn_state;
594607
int *insn_stack;

include/linux/bpfilter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ int bpfilter_ip_set_sockopt(struct sock *sk, int optname, sockptr_t optval,
1111
unsigned int optlen);
1212
int bpfilter_ip_get_sockopt(struct sock *sk, int optname, char __user *optval,
1313
int __user *optlen);
14-
void bpfilter_umh_cleanup(struct umd_info *info);
1514

1615
struct bpfilter_umh_ops {
1716
struct umd_info info;

include/linux/filter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ void bpf_prog_free(struct bpf_prog *fp);
874874

875875
bool bpf_opcode_in_insntable(u8 code);
876876

877-
void bpf_prog_free_linfo(struct bpf_prog *prog);
878877
void bpf_prog_fill_jited_linfo(struct bpf_prog *prog,
879878
const u32 *insn_to_jit_off);
880879
int bpf_prog_alloc_jited_linfo(struct bpf_prog *prog);

include/linux/netdevice.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,6 +5073,15 @@ static inline bool netif_is_l3_slave(const struct net_device *dev)
50735073
return dev->priv_flags & IFF_L3MDEV_SLAVE;
50745074
}
50755075

5076+
static inline int dev_sdif(const struct net_device *dev)
5077+
{
5078+
#ifdef CONFIG_NET_L3_MASTER_DEV
5079+
if (netif_is_l3_slave(dev))
5080+
return dev->ifindex;
5081+
#endif
5082+
return 0;
5083+
}
5084+
50765085
static inline bool netif_is_bridge_master(const struct net_device *dev)
50775086
{
50785087
return dev->priv_flags & IFF_EBRIDGE;

include/net/xdp_sock_drv.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,6 @@ static inline void xsk_buff_free(struct xdp_buff *xdp)
255255
{
256256
}
257257

258-
static inline void xsk_buff_discard(struct xdp_buff *xdp)
259-
{
260-
}
261-
262258
static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
263259
{
264260
}

include/uapi/linux/bpf.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,10 @@ union bpf_attr {
31783178
* **BPF_FIB_LOOKUP_DIRECT**
31793179
* Do a direct table lookup vs full lookup using FIB
31803180
* rules.
3181+
* **BPF_FIB_LOOKUP_TBID**
3182+
* Used with BPF_FIB_LOOKUP_DIRECT.
3183+
* Use the routing table ID present in *params*->tbid
3184+
* for the fib lookup.
31813185
* **BPF_FIB_LOOKUP_OUTPUT**
31823186
* Perform lookup from an egress perspective (default is
31833187
* ingress).
@@ -6832,6 +6836,7 @@ enum {
68326836
BPF_FIB_LOOKUP_DIRECT = (1U << 0),
68336837
BPF_FIB_LOOKUP_OUTPUT = (1U << 1),
68346838
BPF_FIB_LOOKUP_SKIP_NEIGH = (1U << 2),
6839+
BPF_FIB_LOOKUP_TBID = (1U << 3),
68356840
};
68366841

68376842
enum {
@@ -6892,9 +6897,19 @@ struct bpf_fib_lookup {
68926897
__u32 ipv6_dst[4]; /* in6_addr; network order */
68936898
};
68946899

6895-
/* output */
6896-
__be16 h_vlan_proto;
6897-
__be16 h_vlan_TCI;
6900+
union {
6901+
struct {
6902+
/* output */
6903+
__be16 h_vlan_proto;
6904+
__be16 h_vlan_TCI;
6905+
};
6906+
/* input: when accompanied with the
6907+
* 'BPF_FIB_LOOKUP_DIRECT | BPF_FIB_LOOKUP_TBID` flags, a
6908+
* specific routing table to use for the fib lookup.
6909+
*/
6910+
__u32 tbid;
6911+
};
6912+
68986913
__u8 smac[6]; /* ETH_ALEN */
68996914
__u8 dmac[6]; /* ETH_ALEN */
69006915
};

kernel/bpf/bloom_filter.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ static struct bpf_map *bloom_map_alloc(union bpf_attr *attr)
8686
int numa_node = bpf_map_attr_numa_node(attr);
8787
struct bpf_bloom_filter *bloom;
8888

89-
if (!bpf_capable())
90-
return ERR_PTR(-EPERM);
91-
9289
if (attr->key_size != 0 || attr->value_size == 0 ||
9390
attr->max_entries == 0 ||
9491
attr->map_flags & ~BLOOM_CREATE_FLAG_MASK ||

0 commit comments

Comments
 (0)