Skip to content

Commit ec24b98

Browse files
jmberg-intelrichardweinberger
authored andcommitted
um: remove variable stack array in os_rcv_fd_msg()
When generalizing this, I was in the mindset of this being "userspace" code, but even there we should not use variable arrays as the kernel is moving away from allowing that. Simply reserve (but not use) enough space for the maximum two descriptors we might need now, and return an error if attempting to receive more than that. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 431c164 commit ec24b98

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/um/os-Linux/file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ int os_shutdown_socket(int fd, int r, int w)
528528
ssize_t os_rcv_fd_msg(int fd, int *fds, unsigned int n_fds,
529529
void *data, size_t data_len)
530530
{
531-
char buf[CMSG_SPACE(sizeof(*fds) * n_fds)];
531+
#define MAX_RCV_FDS 2
532+
char buf[CMSG_SPACE(sizeof(*fds) * MAX_RCV_FDS)];
532533
struct cmsghdr *cmsg;
533534
struct iovec iov = {
534535
.iov_base = data,
@@ -538,10 +539,13 @@ ssize_t os_rcv_fd_msg(int fd, int *fds, unsigned int n_fds,
538539
.msg_iov = &iov,
539540
.msg_iovlen = 1,
540541
.msg_control = buf,
541-
.msg_controllen = sizeof(buf),
542+
.msg_controllen = CMSG_SPACE(sizeof(*fds) * n_fds),
542543
};
543544
int n;
544545

546+
if (n_fds > MAX_RCV_FDS)
547+
return -EINVAL;
548+
545549
n = recvmsg(fd, &msg, 0);
546550
if (n < 0)
547551
return -errno;

0 commit comments

Comments
 (0)