| @@ -23,6 +23,7 @@ · 22 unmodified lines |
| 23 | 23 | #include <linux/timekeeping.h> |
| 24 | 24 | #include <linux/ctype.h> |
| 25 | 25 | #include <linux/nospec.h> |
| 26 | +#include <uapi/linux/btf.h> |
| 26 | 27 | |
| 27 | 28 | #define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \ |
| 28 | 29 | (map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \ |
| @@ -1565,8 +1566,9 @@ static void bpf_prog_load_fixup_attach_type(union bpf_attr *attr) · 1536 unmodified lines |
| 1565 | 1566 | } |
| 1566 | 1567 | |
| 1567 | 1568 | static int |
| 1568 | | −bpf_prog_load_check_attach_type(enum bpf_prog_type prog_type, |
| 1569 | | − enum bpf_attach_type expected_attach_type) |
| 1569 | +bpf_prog_load_check_attach(enum bpf_prog_type prog_type, |
| 1570 | + enum bpf_attach_type expected_attach_type, |
| 1571 | + u32 btf_id) |
| 1570 | 1572 | { |
| 1571 | 1573 | switch (prog_type) { |
| 1572 | 1574 | case BPF_PROG_TYPE_CGROUP_SOCK: |
| @@ -1608,13 +1610,19 @@ bpf_prog_load_check_attach_type(enum bpf_prog_type prog_type, · 35 unmodified lines |
| 1608 | 1610 | default: |
| 1609 | 1611 | return -EINVAL; |
| 1610 | 1612 | } |
| 1613 | + case BPF_PROG_TYPE_RAW_TRACEPOINT: |
| 1614 | + if (btf_id > BTF_MAX_TYPE) |
| 1615 | + return -EINVAL; |
| 1616 | + return 0; |
| 1611 | 1617 | default: |
| 1618 | + if (btf_id) |
| 1619 | + return -EINVAL; |
| 1612 | 1620 | return 0; |
| 1613 | 1621 | } |
| 1614 | 1622 | } |
| 1615 | 1623 | |
| 1616 | 1624 | /* last field in 'union bpf_attr' used by this command */ |
| 1617 | | −#define BPF_PROG_LOAD_LAST_FIELD line_info_cnt |
| 1625 | +#define BPF_PROG_LOAD_LAST_FIELD attach_btf_id |
| 1618 | 1626 | |
| 1619 | 1627 | static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr) |
| 1620 | 1628 | { |
| @@ -1656,7 +1664,8 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr) · 35 unmodified lines |
| 1656 | 1664 | return -EPERM; |
| 1657 | 1665 | |
| 1658 | 1666 | bpf_prog_load_fixup_attach_type(attr); |
| 1659 | | − if (bpf_prog_load_check_attach_type(type, attr->expected_attach_type)) |
| 1667 | + if (bpf_prog_load_check_attach(type, attr->expected_attach_type, |
| 1668 | + attr->attach_btf_id)) |
| 1660 | 1669 | return -EINVAL; |
| 1661 | 1670 | |
| 1662 | 1671 | /* plain bpf_prog allocation */ |
| @@ -1665,6 +1674,7 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr) · 2 unmodified lines |
| 1665 | 1674 | return -ENOMEM; |
| 1666 | 1675 | |
| 1667 | 1676 | prog->expected_attach_type = attr->expected_attach_type; |
| 1677 | + prog->aux->attach_btf_id = attr->attach_btf_id; |
| 1668 | 1678 | |
| 1669 | 1679 | prog->aux->offload_requested = !!attr->prog_ifindex; |
| 1670 | 1680 | |