Skip to content

Commit d4ecfeb

Browse files
fomichevborkmann
authored andcommitted
bpf: allow wide aligned loads for bpf_sock_addr user_ip6 and msg_src_ip6
Add explicit check for u64 loads of user_ip6 and msg_src_ip6 and update the comment. Cc: Yonghong Song <yhs@fb.com> Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent b439954 commit d4ecfeb

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎include/uapi/linux/bpf.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,7 +3248,7 @@ struct bpf_sock_addr {
32483248
__u32 user_ip4; /* Allows 1,2,4-byte read and 4-byte write.
32493249
* Stored in network byte order.
32503250
*/
3251-
__u32 user_ip6[4]; /* Allows 1,2,4-byte read and 4,8-byte write.
3251+
__u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.
32523252
* Stored in network byte order.
32533253
*/
32543254
__u32 user_port; /* Allows 4-byte read and write.
@@ -3260,7 +3260,7 @@ struct bpf_sock_addr {
32603260
__u32 msg_src_ip4; /* Allows 1,2,4-byte read and 4-byte write.
32613261
* Stored in network byte order.
32623262
*/
3263-
__u32 msg_src_ip6[4]; /* Allows 1,2,4-byte read and 4,8-byte write.
3263+
__u32 msg_src_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.
32643264
* Stored in network byte order.
32653265
*/
32663266
__bpf_md_ptr(struct bpf_sock *, sk);

‎net/core/filter.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6884,9 +6884,19 @@ static bool sock_addr_is_valid_access(int off, int size,
68846884
case bpf_ctx_range(struct bpf_sock_addr, msg_src_ip4):
68856885
case bpf_ctx_range_till(struct bpf_sock_addr, msg_src_ip6[0],
68866886
msg_src_ip6[3]):
6887-
/* Only narrow read access allowed for now. */
68886887
if (type == BPF_READ) {
68896888
bpf_ctx_record_field_size(info, size_default);
6889+
6890+
if (bpf_ctx_wide_access_ok(off, size,
6891+
struct bpf_sock_addr,
6892+
user_ip6))
6893+
return true;
6894+
6895+
if (bpf_ctx_wide_access_ok(off, size,
6896+
struct bpf_sock_addr,
6897+
msg_src_ip6))
6898+
return true;
6899+
68906900
if (!bpf_ctx_narrow_access_ok(off, size, size_default))
68916901
return false;
68926902
} else {

0 commit comments

Comments
 (0)