Skip to content

Commit c9aa81f

Browse files
Tuong Liendavem330
authored andcommitted
tipc: fix kernel WARNING in tipc_msg_append()
syzbot found the following issue: WARNING: CPU: 0 PID: 6808 at include/linux/thread_info.h:150 check_copy_size include/linux/thread_info.h:150 [inline] WARNING: CPU: 0 PID: 6808 at include/linux/thread_info.h:150 copy_from_iter include/linux/uio.h:144 [inline] WARNING: CPU: 0 PID: 6808 at include/linux/thread_info.h:150 tipc_msg_append+0x49a/0x5e0 net/tipc/msg.c:242 Kernel panic - not syncing: panic_on_warn set ... This happens after commit 5e9eecc ("tipc: fix NULL pointer dereference in streaming") that tried to build at least one buffer even when the message data length is zero... However, it now exposes another bug that the 'mss' can be zero and the 'cpy' will be negative, thus the above kernel WARNING will appear! The zero value of 'mss' is never expected because it means Nagle is not enabled for the socket (actually the socket type was 'SOCK_SEQPACKET'), so the function 'tipc_msg_append()' must not be called at all. But that was in this particular case since the message data length was zero, and the 'send <= maxnagle' check became true. We resolve the issue by explicitly checking if Nagle is enabled for the socket, i.e. 'maxnagle != 0' before calling the 'tipc_msg_append()'. We also reinforce the function to against such a negative values if any. Reported-by: [email protected] Fixes: c0bceb9 ("tipc: add smart nagle feature") Acked-by: Jon Maloy <[email protected]> Signed-off-by: Tuong Lien <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 77f972a commit c9aa81f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

net/tipc/msg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ int tipc_msg_append(struct tipc_msg *_hdr, struct msghdr *m, int dlen,
238238
hdr = buf_msg(skb);
239239
curr = msg_blocks(hdr);
240240
mlen = msg_size(hdr);
241-
cpy = min_t(int, rem, mss - mlen);
241+
cpy = min_t(size_t, rem, mss - mlen);
242242
if (cpy != copy_from_iter(skb->data + mlen, cpy, &m->msg_iter))
243243
return -EFAULT;
244244
msg_set_size(hdr, mlen + cpy);
245245
skb_put(skb, cpy);
246246
rem -= cpy;
247247
total += msg_blocks(hdr) - curr;
248-
} while (rem);
248+
} while (rem > 0);
249249
return total - accounted;
250250
}
251251

net/tipc/socket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,8 @@ static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dlen)
15741574
break;
15751575
send = min_t(size_t, dlen - sent, TIPC_MAX_USER_MSG_SIZE);
15761576
blocks = tsk->snd_backlog;
1577-
if (tsk->oneway++ >= tsk->nagle_start && send <= maxnagle) {
1577+
if (tsk->oneway++ >= tsk->nagle_start && maxnagle &&
1578+
send <= maxnagle) {
15781579
rc = tipc_msg_append(hdr, m, send, maxnagle, txq);
15791580
if (unlikely(rc < 0))
15801581
break;

0 commit comments

Comments
 (0)