Add tests for BPF_PROG_TYPE_SK_MSG to test_verifier for read access to new sk fields.
Unified · Split
| @@ -2176,6 +2176,14 @@ enum sk_action { · 2175 unmodified lines | |||
| 2176 | struct sk_msg_md { | 2176 | struct sk_msg_md { |
| 2177 | void *data; | 2177 | void *data; |
| 2178 | void *data_end; | 2178 | void *data_end; |
| 2179 | |||
| 2180 | __u32 family; | ||
| 2181 | __u32 remote_ip4; /* Stored in network byte order */ | ||
| 2182 | __u32 local_ip4; /* Stored in network byte order */ | ||
| 2183 | __u32 remote_ip6[4]; /* Stored in network byte order */ | ||
| 2184 | __u32 local_ip6[4]; /* Stored in network byte order */ | ||
| 2185 | __u32 remote_port; /* Stored in network byte order */ | ||
| 2186 | __u32 local_port; /* stored in host byte order */ | ||
| 2179 | }; | 2187 | }; |
| 2180 | 2188 | ||
| 2181 | #define BPF_TAG_SIZE 8 | 2189 | #define BPF_TAG_SIZE 8 |
| @@ -1685,6 +1685,121 @@ static struct bpf_test tests[] = { · 1684 unmodified lines | |||
| 1685 | .result = ACCEPT, | 1685 | .result = ACCEPT, |
| 1686 | .prog_type = BPF_PROG_TYPE_SK_SKB, | 1686 | .prog_type = BPF_PROG_TYPE_SK_SKB, |
| 1687 | }, | 1687 | }, |
| 1688 | { | ||
| 1689 | "valid access family in SK_MSG", | ||
| 1690 | .insns = { | ||
| 1691 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1692 | offsetof(struct sk_msg_md, family)), | ||
| 1693 | BPF_EXIT_INSN(), | ||
| 1694 | }, | ||
| 1695 | .result = ACCEPT, | ||
| 1696 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1697 | }, | ||
| 1698 | { | ||
| 1699 | "valid access remote_ip4 in SK_MSG", | ||
| 1700 | .insns = { | ||
| 1701 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1702 | offsetof(struct sk_msg_md, remote_ip4)), | ||
| 1703 | BPF_EXIT_INSN(), | ||
| 1704 | }, | ||
| 1705 | .result = ACCEPT, | ||
| 1706 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1707 | }, | ||
| 1708 | { | ||
| 1709 | "valid access local_ip4 in SK_MSG", | ||
| 1710 | .insns = { | ||
| 1711 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1712 | offsetof(struct sk_msg_md, local_ip4)), | ||
| 1713 | BPF_EXIT_INSN(), | ||
| 1714 | }, | ||
| 1715 | .result = ACCEPT, | ||
| 1716 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1717 | }, | ||
| 1718 | { | ||
| 1719 | "valid access remote_port in SK_MSG", | ||
| 1720 | .insns = { | ||
| 1721 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1722 | offsetof(struct sk_msg_md, remote_port)), | ||
| 1723 | BPF_EXIT_INSN(), | ||
| 1724 | }, | ||
| 1725 | .result = ACCEPT, | ||
| 1726 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1727 | }, | ||
| 1728 | { | ||
| 1729 | "valid access local_port in SK_MSG", | ||
| 1730 | .insns = { | ||
| 1731 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1732 | offsetof(struct sk_msg_md, local_port)), | ||
| 1733 | BPF_EXIT_INSN(), | ||
| 1734 | }, | ||
| 1735 | .result = ACCEPT, | ||
| 1736 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1737 | }, | ||
| 1738 | { | ||
| 1739 | "valid access remote_ip6 in SK_MSG", | ||
| 1740 | .insns = { | ||
| 1741 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1742 | offsetof(struct sk_msg_md, remote_ip6[0])), | ||
| 1743 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1744 | offsetof(struct sk_msg_md, remote_ip6[1])), | ||
| 1745 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1746 | offsetof(struct sk_msg_md, remote_ip6[2])), | ||
| 1747 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1748 | offsetof(struct sk_msg_md, remote_ip6[3])), | ||
| 1749 | BPF_EXIT_INSN(), | ||
| 1750 | }, | ||
| 1751 | .result = ACCEPT, | ||
| 1752 | .prog_type = BPF_PROG_TYPE_SK_SKB, | ||
| 1753 | }, | ||
| 1754 | { | ||
| 1755 | "valid access local_ip6 in SK_MSG", | ||
| 1756 | .insns = { | ||
| 1757 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1758 | offsetof(struct sk_msg_md, local_ip6[0])), | ||
| 1759 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1760 | offsetof(struct sk_msg_md, local_ip6[1])), | ||
| 1761 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1762 | offsetof(struct sk_msg_md, local_ip6[2])), | ||
| 1763 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, | ||
| 1764 | offsetof(struct sk_msg_md, local_ip6[3])), | ||
| 1765 | BPF_EXIT_INSN(), | ||
| 1766 | }, | ||
| 1767 | .result = ACCEPT, | ||
| 1768 | .prog_type = BPF_PROG_TYPE_SK_SKB, | ||
| 1769 | }, | ||
| 1770 | { | ||
| 1771 | "invalid 64B read of family in SK_MSG", | ||
| 1772 | .insns = { | ||
| 1773 | BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, | ||
| 1774 | offsetof(struct sk_msg_md, family)), | ||
| 1775 | BPF_EXIT_INSN(), | ||
| 1776 | }, | ||
| 1777 | .errstr = "invalid bpf_context access", | ||
| 1778 | .result = REJECT, | ||
| 1779 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1780 | }, | ||
| 1781 | { | ||
| 1782 | "invalid read past end of SK_MSG", | ||
| 1783 | .insns = { | ||
| 1784 | BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, | ||
| 1785 | offsetof(struct sk_msg_md, local_port) + 4), | ||
| 1786 | BPF_EXIT_INSN(), | ||
| 1787 | }, | ||
| 1788 | .errstr = "R0 !read_ok", | ||
| 1789 | .result = REJECT, | ||
| 1790 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1791 | }, | ||
| 1792 | { | ||
| 1793 | "invalid read offset in SK_MSG", | ||
| 1794 | .insns = { | ||
| 1795 | BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, | ||
| 1796 | offsetof(struct sk_msg_md, family) + 1), | ||
| 1797 | BPF_EXIT_INSN(), | ||
| 1798 | }, | ||
| 1799 | .errstr = "invalid bpf_context access", | ||
| 1800 | .result = REJECT, | ||
| 1801 | .prog_type = BPF_PROG_TYPE_SK_MSG, | ||
| 1802 | }, | ||
| 1688 | { | 1803 | { |
| 1689 | "direct packet read for SK_MSG", | 1804 | "direct packet read for SK_MSG", |
| 1690 | .insns = { | 1805 | .insns = { |