Commit e133938
bpf: Use __u64 to save the bits in bits iterator
On 32-bit hosts (e.g., arm32), when a bpf program passes a u64 to
bpf_iter_bits_new(), bpf_iter_bits_new() will use bits_copy to store the
content of the u64. However, bits_copy is only 4 bytes, leading to stack
corruption.
The straightforward solution would be to replace u64 with unsigned long
in bpf_iter_bits_new(). However, this introduces confusion and problems
for 32-bit hosts because the size of ulong in bpf program is 8 bytes,
but it is treated as 4-bytes after passed to bpf_iter_bits_new().
Fix it by changing the type of both bits and bit_count from unsigned
long to u64. However, the change is not enough. The main reason is that
bpf_iter_bits_next() uses find_next_bit() to find the next bit and the
pointer passed to find_next_bit() is an unsigned long pointer instead
of a u64 pointer. For 32-bit little-endian host, it is fine but it is
not the case for 32-bit big-endian host. Because under 32-bit big-endian
host, the first iterated unsigned long will be the bits 32-63 of the u64
instead of the expected bits 0-31. Therefore, in addition to changing
the type, swap the two unsigned longs within the u64 for 32-bit
big-endian host.
Signed-off-by: Hou Tao <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>1 parent 393397f commit e133938
1 file changed
+30
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2855 | 2855 | | |
2856 | 2856 | | |
2857 | 2857 | | |
2858 | | - | |
2859 | | - | |
| 2858 | + | |
| 2859 | + | |
2860 | 2860 | | |
2861 | 2861 | | |
2862 | 2862 | | |
2863 | 2863 | | |
2864 | 2864 | | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
2865 | 2888 | | |
2866 | 2889 | | |
2867 | 2890 | | |
| |||
2904 | 2927 | | |
2905 | 2928 | | |
2906 | 2929 | | |
| 2930 | + | |
| 2931 | + | |
2907 | 2932 | | |
2908 | 2933 | | |
2909 | 2934 | | |
| |||
2922 | 2947 | | |
2923 | 2948 | | |
2924 | 2949 | | |
| 2950 | + | |
| 2951 | + | |
2925 | 2952 | | |
2926 | 2953 | | |
2927 | 2954 | | |
| |||
2939 | 2966 | | |
2940 | 2967 | | |
2941 | 2968 | | |
2942 | | - | |
| 2969 | + | |
2943 | 2970 | | |
2944 | 2971 | | |
2945 | 2972 | | |
| |||
0 commit comments