|
|
404da3 |
From 682b0ccabdc7970f89544c0d19477515583a5f5b Mon Sep 17 00:00:00 2001
|
|
|
404da3 |
From: Beniamino Galvani <bgalvani@redhat.com>
|
|
|
404da3 |
Date: Thu, 25 Feb 2021 14:38:16 +0100
|
|
|
404da3 |
Subject: [PATCH] libndp,ndptool: use poll() instead of select()
|
|
|
404da3 |
|
|
|
404da3 |
select() doesn't support file descriptors greater than 1023. If the
|
|
|
404da3 |
program has many files open, the socket descriptor can be > 1023 and
|
|
|
404da3 |
then FD_SET(fd, &rfds) causes a buffer overflow.
|
|
|
404da3 |
|
|
|
404da3 |
Switch to poll() and ppoll() which don't have this limitation.
|
|
|
404da3 |
|
|
|
404da3 |
Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
|
|
|
404da3 |
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
|
|
|
404da3 |
---
|
|
|
404da3 |
libndp/libndp.c | 20 +++++++++-----------
|
|
|
404da3 |
utils/Makefile.am | 2 +-
|
|
|
404da3 |
utils/Makefile.in | 2 +-
|
|
|
404da3 |
utils/ndptool.c | 22 +++++++++-------------
|
|
|
404da3 |
4 files changed, 20 insertions(+), 26 deletions(-)
|
|
|
404da3 |
|
|
|
404da3 |
diff --git a/libndp/libndp.c b/libndp/libndp.c
|
|
|
404da3 |
index 06a3d23..6314717 100644
|
|
|
404da3 |
--- a/libndp/libndp.c
|
|
|
404da3 |
+++ b/libndp/libndp.c
|
|
|
404da3 |
@@ -25,7 +25,7 @@
|
|
|
404da3 |
#include <errno.h>
|
|
|
404da3 |
#include <ctype.h>
|
|
|
404da3 |
#include <sys/socket.h>
|
|
|
404da3 |
-#include <sys/select.h>
|
|
|
404da3 |
+#include <poll.h>
|
|
|
404da3 |
#include <netinet/in.h>
|
|
|
404da3 |
#include <netinet/icmp6.h>
|
|
|
404da3 |
#include <arpa/inet.h>
|
|
|
404da3 |
@@ -2107,22 +2107,20 @@ int ndp_call_eventfd_handler(struct ndp *ndp)
|
|
|
404da3 |
NDP_EXPORT
|
|
|
404da3 |
int ndp_callall_eventfd_handler(struct ndp *ndp)
|
|
|
404da3 |
{
|
|
|
404da3 |
- fd_set rfds;
|
|
|
404da3 |
- int fdmax;
|
|
|
404da3 |
- struct timeval tv;
|
|
|
404da3 |
- int fd = ndp_get_eventfd(ndp);
|
|
|
404da3 |
+ struct pollfd pfd;
|
|
|
404da3 |
int ret;
|
|
|
404da3 |
int err;
|
|
|
404da3 |
|
|
|
404da3 |
- memset(&tv, 0, sizeof(tv));
|
|
|
404da3 |
- FD_ZERO(&rfds);
|
|
|
404da3 |
- FD_SET(fd, &rfds);
|
|
|
404da3 |
- fdmax = fd + 1;
|
|
|
404da3 |
+ pfd = (struct pollfd) {
|
|
|
404da3 |
+ .fd = ndp_get_eventfd(ndp),
|
|
|
404da3 |
+ .events = POLLIN,
|
|
|
404da3 |
+ };
|
|
|
404da3 |
+
|
|
|
404da3 |
while (true) {
|
|
|
404da3 |
- ret = select(fdmax, &rfds, NULL, NULL, &tv;;
|
|
|
404da3 |
+ ret = poll(&pfd, 1, 0);
|
|
|
404da3 |
if (ret == -1)
|
|
|
404da3 |
return -errno;
|
|
|
404da3 |
- if (!FD_ISSET(fd, &rfds))
|
|
|
404da3 |
+ if (!(pfd.revents & POLLIN))
|
|
|
404da3 |
return 0;
|
|
|
404da3 |
err = ndp_call_eventfd_handler(ndp);
|
|
|
404da3 |
if (err)
|
|
|
404da3 |
diff --git a/utils/Makefile.am b/utils/Makefile.am
|
|
|
404da3 |
index cca00c2..75e452c 100644
|
|
|
404da3 |
--- a/utils/Makefile.am
|
|
|
404da3 |
+++ b/utils/Makefile.am
|
|
|
404da3 |
@@ -2,7 +2,7 @@ MAINTAINERCLEANFILES = Makefile.in
|
|
|
404da3 |
|
|
|
404da3 |
ACLOCAL_AMFLAGS = -I m4
|
|
|
404da3 |
|
|
|
404da3 |
-AM_CFLAGS = -I${top_srcdir}/include
|
|
|
404da3 |
+AM_CFLAGS = -I${top_srcdir}/include -D_GNU_SOURCE
|
|
|
404da3 |
|
|
|
404da3 |
ndptool_LDADD = $(top_builddir)/libndp/libndp.la
|
|
|
404da3 |
|
|
|
404da3 |
diff --git a/utils/Makefile.in b/utils/Makefile.in
|
|
|
404da3 |
index e339b19..d81de50 100644
|
|
|
404da3 |
--- a/utils/Makefile.in
|
|
|
404da3 |
+++ b/utils/Makefile.in
|
|
|
404da3 |
@@ -294,7 +294,7 @@ top_builddir = @top_builddir@
|
|
|
404da3 |
top_srcdir = @top_srcdir@
|
|
|
404da3 |
MAINTAINERCLEANFILES = Makefile.in
|
|
|
404da3 |
ACLOCAL_AMFLAGS = -I m4
|
|
|
404da3 |
-AM_CFLAGS = -I${top_srcdir}/include
|
|
|
404da3 |
+AM_CFLAGS = -I${top_srcdir}/include -D_GNU_SOURCE
|
|
|
404da3 |
ndptool_LDADD = $(top_builddir)/libndp/libndp.la
|
|
|
404da3 |
ndptool_SOURCES = ndptool.c
|
|
|
404da3 |
all: all-am
|
|
|
404da3 |
diff --git a/utils/ndptool.c b/utils/ndptool.c
|
|
|
404da3 |
index 662ff01..618f167 100644
|
|
|
404da3 |
--- a/utils/ndptool.c
|
|
|
404da3 |
+++ b/utils/ndptool.c
|
|
|
404da3 |
@@ -28,7 +28,7 @@
|
|
|
404da3 |
#include <arpa/inet.h>
|
|
|
404da3 |
#include <errno.h>
|
|
|
404da3 |
#include <ndp.h>
|
|
|
404da3 |
-#include <sys/select.h>
|
|
|
404da3 |
+#include <poll.h>
|
|
|
404da3 |
|
|
|
404da3 |
enum verbosity_level {
|
|
|
404da3 |
VERB1,
|
|
|
404da3 |
@@ -59,13 +59,10 @@ static void empty_signal_handler(int signal)
|
|
|
404da3 |
|
|
|
404da3 |
static int run_main_loop(struct ndp *ndp)
|
|
|
404da3 |
{
|
|
|
404da3 |
- fd_set rfds;
|
|
|
404da3 |
- fd_set rfds_tmp;
|
|
|
404da3 |
- int fdmax;
|
|
|
404da3 |
+ struct pollfd pfd;
|
|
|
404da3 |
int ret;
|
|
|
404da3 |
struct sigaction siginfo;
|
|
|
404da3 |
sigset_t mask;
|
|
|
404da3 |
- int ndp_fd;
|
|
|
404da3 |
int err = 0;
|
|
|
404da3 |
|
|
|
404da3 |
sigemptyset(&siginfo.sa_mask);
|
|
|
404da3 |
@@ -100,23 +97,22 @@ static int run_main_loop(struct ndp *ndp)
|
|
|
404da3 |
|
|
|
404da3 |
sigemptyset(&mask);
|
|
|
404da3 |
|
|
|
404da3 |
- FD_ZERO(&rfds);
|
|
|
404da3 |
- ndp_fd = ndp_get_eventfd(ndp);
|
|
|
404da3 |
- FD_SET(ndp_fd, &rfds);
|
|
|
404da3 |
- fdmax = ndp_fd + 1;
|
|
|
404da3 |
+ pfd = (struct pollfd) {
|
|
|
404da3 |
+ .fd = ndp_get_eventfd(ndp),
|
|
|
404da3 |
+ .events = POLLIN,
|
|
|
404da3 |
+ };
|
|
|
404da3 |
|
|
|
404da3 |
for (;;) {
|
|
|
404da3 |
- rfds_tmp = rfds;
|
|
|
404da3 |
- ret = pselect(fdmax, &rfds_tmp, NULL, NULL, NULL, &mask);
|
|
|
404da3 |
+ ret = ppoll(&pfd, 1, NULL, &mask);
|
|
|
404da3 |
if (ret == -1) {
|
|
|
404da3 |
if (errno == EINTR) {
|
|
|
404da3 |
goto out;
|
|
|
404da3 |
}
|
|
|
404da3 |
- pr_err("Select failed\n");
|
|
|
404da3 |
+ pr_err("Poll failed\n");
|
|
|
404da3 |
err = -errno;
|
|
|
404da3 |
goto out;
|
|
|
404da3 |
}
|
|
|
404da3 |
- if (FD_ISSET(ndp_fd, &rfds_tmp)) {
|
|
|
404da3 |
+ if (pfd.revents & POLLIN) {
|
|
|
404da3 |
err = ndp_call_eventfd_handler(ndp);
|
|
|
404da3 |
if (err) {
|
|
|
404da3 |
pr_err("ndp eventfd handler call failed\n");
|
|
|
404da3 |
--
|
|
|
404da3 |
2.26.2
|
|
|
404da3 |
|