Skip to content

Commit dcda138

Browse files
Sjur Braendelanddavem330
authored andcommitted
caif: Bugfix - use MSG_TRUNC in receive
Fixed handling when skb don't fit in user buffer, instead of returning -EMSGSIZE, the buffer is truncated (just as unix seqpakcet does). Signed-off-by: Sjur Braendeland <sjur.brandeland@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a9a8f10 commit dcda138

1 file changed

Lines changed: 18 additions & 29 deletions

File tree

‎net/caif/caif_socket.c‎

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -292,53 +292,42 @@ static void caif_check_flow_release(struct sock *sk)
292292
caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
293293
}
294294
}
295+
295296
/*
296-
* Copied from sock.c:sock_queue_rcv_skb(), and added check that user buffer
297-
* has sufficient size.
297+
* Copied from unix_dgram_recvmsg, but removed credit checks,
298+
* changed locking, address handling and added MSG_TRUNC.
298299
*/
299-
300300
static int caif_seqpkt_recvmsg(struct kiocb *iocb, struct socket *sock,
301-
struct msghdr *m, size_t buf_len, int flags)
301+
struct msghdr *m, size_t len, int flags)
302302

303303
{
304304
struct sock *sk = sock->sk;
305305
struct sk_buff *skb;
306-
int ret = 0;
307-
int len;
306+
int ret;
307+
int copylen;
308308

309-
if (unlikely(!buf_len))
310-
return -EINVAL;
309+
ret = -EOPNOTSUPP;
310+
if (m->msg_flags&MSG_OOB)
311+
goto read_error;
311312

312313
skb = skb_recv_datagram(sk, flags, 0 , &ret);
313314
if (!skb)
314315
goto read_error;
315-
316-
len = skb->len;
317-
318-
if (skb && skb->len > buf_len && !(flags & MSG_PEEK)) {
319-
len = buf_len;
320-
/*
321-
* Push skb back on receive queue if buffer too small.
322-
* This has a built-in race where multi-threaded receive
323-
* may get packet in wrong order, but multiple read does
324-
* not really guarantee ordered delivery anyway.
325-
* Let's optimize for speed without taking locks.
326-
*/
327-
328-
skb_queue_head(&sk->sk_receive_queue, skb);
329-
ret = -EMSGSIZE;
330-
goto read_error;
316+
copylen = skb->len;
317+
if (len < copylen) {
318+
m->msg_flags |= MSG_TRUNC;
319+
copylen = len;
331320
}
332321

333-
ret = skb_copy_datagram_iovec(skb, 0, m->msg_iov, len);
322+
ret = skb_copy_datagram_iovec(skb, 0, m->msg_iov, copylen);
334323
if (ret)
335-
goto read_error;
324+
goto out_free;
336325

326+
ret = (flags & MSG_TRUNC) ? skb->len : copylen;
327+
out_free:
337328
skb_free_datagram(sk, skb);
338-
339329
caif_check_flow_release(sk);
340-
341-
return len;
330+
return ret;
342331

343332
read_error:
344333
return ret;

0 commit comments

Comments
 (0)