Skip to content

Commit 4368640

Browse files
jsitnickidavem330
authored andcommitted
selftests/net: Interpret UDP_GRO cmsg data as an int value
Data passed to user-space with a (SOL_UDP, UDP_GRO) cmsg carries an int (see udp_cmsg_recv), not a u16 value, as strace confirms: recvmsg(8, {msg_name=..., msg_iov=[{iov_base="\0\0..."..., iov_len=96000}], msg_iovlen=1, msg_control=[{cmsg_len=20, <-- sizeof(cmsghdr) + 4 cmsg_level=SOL_UDP, cmsg_type=0x68}], <-- UDP_GRO msg_controllen=24, msg_flags=0}, 0) = 11200 Interpreting the data as an u16 value won't work on big-endian platforms. Since it is too late to back out of this API decision [1], fix the test. [1]: https://lore.kernel.org/netdev/[email protected]/ Fixes: 3327a9c ("selftests: add functionals test for UDP GRO") Suggested-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Sitnicki <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 908d4bb commit 4368640

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

tools/testing/selftests/net/udpgso_bench_rx.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,10 @@ static void do_verify_udp(const char *data, int len)
214214

215215
static int recv_msg(int fd, char *buf, int len, int *gso_size)
216216
{
217-
char control[CMSG_SPACE(sizeof(uint16_t))] = {0};
217+
char control[CMSG_SPACE(sizeof(int))] = {0};
218218
struct msghdr msg = {0};
219219
struct iovec iov = {0};
220220
struct cmsghdr *cmsg;
221-
uint16_t *gsosizeptr;
222221
int ret;
223222

224223
iov.iov_base = buf;
@@ -237,8 +236,7 @@ static int recv_msg(int fd, char *buf, int len, int *gso_size)
237236
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
238237
if (cmsg->cmsg_level == SOL_UDP
239238
&& cmsg->cmsg_type == UDP_GRO) {
240-
gsosizeptr = (uint16_t *) CMSG_DATA(cmsg);
241-
*gso_size = *gsosizeptr;
239+
*gso_size = *(int *)CMSG_DATA(cmsg);
242240
break;
243241
}
244242
}

0 commit comments

Comments
 (0)