From df5d1f220bb0f9ee8feb944ffa2f4a96b8df9c7a Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Tue, 24 May 2022 12:35:38 +0200 Subject: [PATCH] modem: simcom-sim7080: do not send fragmented data as multiple datagrams Check if there are multiple non-empty data fragments passed to sendmsg() function. If positive, then set EMSGSIZE errno and return -1, as that case is not handled properly with current implementation. Signed-off-by: Marcin Niestroj --- drivers/modem/simcom-sim7080.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/modem/simcom-sim7080.c b/drivers/modem/simcom-sim7080.c index dfcfb49f5b9..958b00837cc 100644 --- a/drivers/modem/simcom-sim7080.c +++ b/drivers/modem/simcom-sim7080.c @@ -447,6 +447,7 @@ exit: */ static ssize_t offload_sendmsg(void *obj, const struct msghdr *msg, int flags) { + struct modem_socket *sock = obj; ssize_t sent = 0; const char *buf; size_t len; @@ -458,6 +459,17 @@ static ssize_t offload_sendmsg(void *obj, const struct msghdr *msg, int flags) return -EAGAIN; } + if (sock->type == SOCK_DGRAM) { + /* + * Current implementation only handles single contiguous fragment at a time, so + * prevent sending multiple datagrams. + */ + if (msghdr_non_empty_iov_count(msg) > 1) { + errno = EMSGSIZE; + return -1; + } + } + for (int i = 0; i < msg->msg_iovlen; i++) { buf = msg->msg_iov[i].iov_base; len = msg->msg_iov[i].iov_len;