Skip to contentSkip to conversation

avc_open() and netlink_loop()

PATCH In review KaiGai Kohei 2 participants 8 messages Feb 3, 2010 – Mar 8, 2010 SELinux security module

lore
Share & tools
lore
#0 lore raw

When we initialize userspace avc using avc_open(3), it internally calls avc_init(3) without any callback functions. The avc_init() is introduced as a deprecated interface from application code, so it is recommended to use avc_open() instead for new applications.

The avc_init() internally calls avc_netlink_open(). If no thread callback is not given, the 'blocking' argument shall be 0, then avc_netlink_open() set O_NONBLOCK flag on the socket file descriptor.

Next, application will create a thread to receive messages via netlink socket to invalidate userspace avc, using avc_netlink_loop(). However, if userspace avc of libselinux is already initialized, the avc_netlink_loop() immediately returns with EWOULDBLOCK, because the netlink socket is not blocked and avc_netlink_receive() does not expect recvfrom() returns error.

It seems to me O_NONBLOCK is a wrong strategy in this case, and select(2) should be checked in avc_netlink_check_nb() instead.

Eamon, what is your opinion?

Signature · 7 lines
OSS Platform Development Division, NEC
KaiGai Kohei <[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 16 lines · KaiGai Kohei

When we initialize userspace avc using avc_open(3), it internally calls avc_init(3) without any callback functions. The avc_init() is introduced as a deprecated interface from application code, so it is recommended to use avc_open() instead for new applications.

The avc_init() internally calls avc_netlink_open(). If no thread callback is not given, the 'blocking' argument shall be 0, then avc_netlink_open() set O_NONBLOCK flag on the socket file descriptor.

Next, application will create a thread to receive messages via netlink socket to invalidate userspace avc, using avc_netlink_loop(). However, if userspace avc of libselinux is already initialized, the avc_netlink_loop() immediately returns with EWOULDBLOCK, because the netlink socket is not blocked and avc_netlink_receive() does not expect recvfrom() returns error.

Quoted 5 lines

It seems to me O_NONBLOCK is a wrong strategy in this case, and select(2) should be checked in avc_netlink_check_nb() instead.

Eamon, what is your opinion?

Hi, my apologies for the delayed response. Yes it appears as though this is a bug. I think the solution is to configure the file descriptor in blocking mode at the start of avc_netlink_loop(). When avc_netlink_loop() is called, we always want blocking behavior. See the attached patch.

Signature · 2 lines
Eamon Walsh 
National Security Agency
libselinux/src/avc.c +1 -1
index 881b915..5c8def0 100644
@@ -222,7 +222,7 @@ int avc_init(const char *prefix,
 		avc_enforcing = rc;
 	}
 
-	rc = avc_netlink_open(avc_using_threads);
+	rc = avc_netlink_open(0);
 	if (rc < 0) {
 		avc_log(SELINUX_ERROR,
 			"%s:  can't open netlink socket: %d (%s)\n",
libselinux/src/avc_internal.c +2 -0
index 8372f52..90dfa51 100644
@@ -233,6 +233,8 @@ void avc_netlink_loop(void)
 	int rc;
 	char buf[1024] __attribute__ ((aligned));
 
+	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK)
+
 	while (1) {
 		errno = 0;
 		rc = avc_netlink_receive(buf, sizeof(buf));
#2 lore raw
Quoted 24 lines · Eamon Walsh
Quoted 16 lines · KaiGai Kohei

When we initialize userspace avc using avc_open(3), it internally calls avc_init(3) without any callback functions. The avc_init() is introduced as a deprecated interface from application code, so it is recommended to use avc_open() instead for new applications.

The avc_init() internally calls avc_netlink_open(). If no thread callback is not given, the 'blocking' argument shall be 0, then avc_netlink_open() set O_NONBLOCK flag on the socket file descriptor.

Next, application will create a thread to receive messages via netlink socket to invalidate userspace avc, using avc_netlink_loop(). However, if userspace avc of libselinux is already initialized, the avc_netlink_loop() immediately returns with EWOULDBLOCK, because the netlink socket is not blocked and avc_netlink_receive() does not expect recvfrom() returns error.

Quoted 5 lines

It seems to me O_NONBLOCK is a wrong strategy in this case, and select(2) should be checked in avc_netlink_check_nb() instead.

Eamon, what is your opinion?

Quoted 7 lines

Hi, my apologies for the delayed response. Yes it appears as though this is a bug. I think the solution is to configure the file descriptor in blocking mode at the start of avc_netlink_loop(). When avc_netlink_loop() is called, we always want blocking behavior. See the attached patch.

Also, before you launch a thread to run avc_netlink_loop(), you need to call avc_netlink_acquire_fd(). Otherwise, the avc will internally make calls to avc_netlink_check_nb() which will not work properly.

Signature · 8 lines
Eamon Walsh 
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw

PATCH 1/1 libselinux: fix avc_netlink_loop() error caused by nonblocking mode.

avc_open() creates the netlink socket in nonblocking mode. If the application later takes control of the netlink socket with avc_netlink_acquire_fd() and then calls avc_netlink_loop(), it will fail with EWOULDBLOCK.

To remedy this, remove the O_NONBLOCK flag from the netlink socket at the start of avc_netlink_loop(). Also, with this fix, there is no need for avc_open() to ever create a blocking socket, so change that and update the man page.

---

 man/man3/avc_netlink_loop.3 |    5 +----
 src/avc.c                   |    2 +-
 src/avc_internal.c          |    2 ++
 3 files changed, 4 insertions(+), 5 deletions(-)
libselinux/man/man3/avc_netlink_loop.3 +1 -4
index 67df6e4..7d8c9a4 100644
@@ -43,10 +43,7 @@ to take ownership of it in application code.  The
 .I blocking
 argument specifies whether read operations on the socket will block.
 .BR avc_open (3)
-calls this function internally, specifying non-blocking behavior (unless
-threading callbacks were explicitly set using the deprecated
-.BR avc_init (3)
-interface, in which case blocking behavior is set).
+calls this function internally, specifying non-blocking behavior.
 
 .B avc_netlink_close
 closes the netlink socket.  This function is called automatically by
libselinux/src/avc.c +1 -1
index 881b915..5c8def0 100644
@@ -222,7 +222,7 @@ int avc_init(const char *prefix,
 		avc_enforcing = rc;
 	}
 
-	rc = avc_netlink_open(avc_using_threads);
+	rc = avc_netlink_open(0);
 	if (rc < 0) {
 		avc_log(SELINUX_ERROR,
 			"%s:  can't open netlink socket: %d (%s)\n",
libselinux/src/avc_internal.c +2 -0
index 8372f52..90dfa51 100644
@@ -233,6 +233,8 @@ void avc_netlink_loop(void)
 	int rc;
 	char buf[1024] __attribute__ ((aligned));
 
+	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
+
 	while (1) {
 		errno = 0;
 		rc = avc_netlink_receive(buf, sizeof(buf));

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw

Re: [PATCH] libselinux: fix avc_netlink_loop() error caused by nonblocking mode.

Quoted 9 lines · Eamon Walsh

avc_open() creates the netlink socket in nonblocking mode. If the application later takes control of the netlink socket with avc_netlink_acquire_fd() and then calls avc_netlink_loop(), it will fail with EWOULDBLOCK.

To remedy this, remove the O_NONBLOCK flag from the netlink socket at the start of avc_netlink_loop(). Also, with this fix, there is no need for avc_open() to ever create a blocking socket, so change that and update the man page.

Apart from this design is sane, the libselinux allows applications to call avc_netlink_check_nb() directly.
If we call the function although its worker thread calls avc_netlink_loop(), the invocation of avc_netlink_check_nb() can be blocked, because it assumes the internal netlink socket is non-blocking mode.
(Of course, we will not see the matter in most of sane applications.)

I think a better approach is to put select(2) with zero or infinite timeout just before avc_netlink_receive() calls to check whether the unread message is in the netlink socket, or not.
And the 'blocking' argument of avc_netlink_open() shall be obsoleted, because this design makes nonsense whether the socket has O_NONBLOCK flag, or not.

The point is we should not assume the netlink socket has a certain state when we call avc_netlink_loop() and avc_netlink_check_nb().

What is your opinion?

Quoted 59 lines

---

  man/man3/avc_netlink_loop.3 |    5 +----
  src/avc.c                   |    2 +-
  src/avc_internal.c          |    2 ++
  3 files changed, 4 insertions(+), 5 deletions(-)
libselinux/man/man3/avc_netlink_loop.3 +1 -4
index 67df6e4..7d8c9a4 100644
@@ -43,10 +43,7 @@ to take ownership of it in application code.  The
  .I blocking
  argument specifies whether read operations on the socket will block.
  .BR avc_open (3)
-calls this function internally, specifying non-blocking behavior (unless
-threading callbacks were explicitly set using the deprecated
-.BR avc_init (3)
-interface, in which case blocking behavior is set).
+calls this function internally, specifying non-blocking behavior.
 
  .B avc_netlink_close
  closes the netlink socket.  This function is called automatically by
libselinux/src/avc.c +1 -1
index 881b915..5c8def0 100644
@@ -222,7 +222,7 @@ int avc_init(const char *prefix,
  		avc_enforcing = rc;
  	}
 
-	rc = avc_netlink_open(avc_using_threads);
+	rc = avc_netlink_open(0);
  	if (rc<  0) {
  		avc_log(SELINUX_ERROR,
  			"%s:  can't open netlink socket: %d (%s)\n",
libselinux/src/avc_internal.c +2 -1
index 8372f52..90dfa51 100644
@@ -233,6 +233,8 @@ void avc_netlink_loop(void)
  	int rc;
  	char buf[1024] __attribute__ ((aligned));
 
+	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)&  ~O_NONBLOCK);
+
  	while (1) {
  		errno = 0;
  		rc = avc_netlink_receive(buf, sizeof(buf));
 
 
 
--

This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Signature · 6 lines
KaiGai Kohei <[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw

Re: [PATCH] libselinux: fix avc_netlink_loop() error caused by nonblocking mode.

Quoted 19 lines · KaiGai Kohei
Quoted 10 lines · Eamon Walsh

avc_open() creates the netlink socket in nonblocking mode. If the application later takes control of the netlink socket with avc_netlink_acquire_fd() and then calls avc_netlink_loop(), it will fail with EWOULDBLOCK.

To remedy this, remove the O_NONBLOCK flag from the netlink socket at the start of avc_netlink_loop(). Also, with this fix, there is no need for avc_open() to ever create a blocking socket, so change that and update the man page.

Apart from this design is sane, the libselinux allows applications to call avc_netlink_check_nb() directly.
If we call the function although its worker thread calls avc_netlink_loop(), the invocation of avc_netlink_check_nb() can be blocked, because it assumes the internal netlink socket is non-blocking mode.
(Of course, we will not see the matter in most of sane applications.)

Quoted 7 lines

I think a better approach is to put select(2) with zero or infinite timeout just before avc_netlink_receive() calls to check whether the unread message is in the netlink socket, or not.
And the 'blocking' argument of avc_netlink_open() shall be obsoleted, because this design makes nonsense whether the socket has O_NONBLOCK flag, or not.

OK I see your point. How about the following:

libselinux: fix avc_netlink_loop() error caused by nonblocking mode.

avc_open() creates the netlink socket in nonblocking mode. If the application later takes control of the netlink socket with avc_netlink_acquire_fd() and then calls avc_netlink_loop(), it will fail with EWOULDBLOCK.

To remedy this, remove the O_NONBLOCK flag from the netlink socket at the start of avc_netlink_loop(). Also, with this fix, there is no need for avc_open() to ever create a blocking socket, so change that and update the man page.

-v2: use poll() in avc_netlink_check_nb(). This makes both avc_netlink_loop() and avc_netlink_check_nb() independent of the O_NONBLOCK flag.

--

 man/man3/avc_netlink_loop.3 |   11 +++--------
 src/avc.c                   |    2 +-
 src/avc_internal.c          |   13 +++++++++++++
 3 files changed, 17 insertions(+), 9 deletions(-)
libselinux/man/man3/avc_netlink_loop.3 +3 -8
index 67df6e4..785be4c 100644
@@ -41,12 +41,9 @@ descriptor is stored internally; use
 .BR avc_netlink_acquire_fd (3)
 to take ownership of it in application code.  The
 .I blocking
-argument specifies whether read operations on the socket will block.
+argument controls whether the O_NONBLOCK flag is set on the socket descriptor.
 .BR avc_open (3)
-calls this function internally, specifying non-blocking behavior (unless
-threading callbacks were explicitly set using the deprecated
-.BR avc_init (3)
-interface, in which case blocking behavior is set).
+calls this function internally, specifying non-blocking behavior.
 
 .B avc_netlink_close
 closes the netlink socket.  This function is called automatically by
@@ -66,9 +63,7 @@ checks the netlink socket for pending messages and processes them.
 Callbacks for policyload and enforcing changes will be called;
 see
 .BR selinux_set_callback (3).
-This function does not block unless
-.BR avc_netlink_open (3)
-specified blocking behavior.
+This function does not block.
 
 .B avc_netlink_loop
 enters a loop blocking on the netlink socket and processing messages as they
libselinux/src/avc.c +1 -1
index 881b915..5c8def0 100644
@@ -222,7 +222,7 @@ int avc_init(const char *prefix,
 		avc_enforcing = rc;
 	}
 
-	rc = avc_netlink_open(avc_using_threads);
+	rc = avc_netlink_open(0);
 	if (rc < 0) {
 		avc_log(SELINUX_ERROR,
 			"%s:  can't open netlink socket: %d (%s)\n",
libselinux/src/avc_internal.c +13 -0
index 8372f52..7a39c61 100644
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <poll.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <linux/types.h>
@@ -205,8 +206,18 @@ int avc_netlink_check_nb(void)
 {
 	int rc;
 	char buf[1024] __attribute__ ((aligned));
+	struct pollfd pfd = { fd, POLLIN | POLLPRI, 0 };
 
 	while (1) {
+		rc = poll(&pfd, 1, 0);
+		if (rc == 0)
+			return 0;
+		if (rc < 0) {
+			avc_log(SELINUX_ERROR, "%s:  netlink poll: error %d\n",
+				avc_prefix, errno);
+			return rc;
+		}
+
 		errno = 0;
 		rc = avc_netlink_receive(buf, sizeof(buf));
 		if (rc < 0) {
@@ -233,6 +244,8 @@ void avc_netlink_loop(void)
 	int rc;
 	char buf[1024] __attribute__ ((aligned));
 
+	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
+
 	while (1) {
 		errno = 0;
 		rc = avc_netlink_receive(buf, sizeof(buf));
Signature · 8 lines
Eamon Walsh 
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#6 lore raw

Re: [PATCH] libselinux: fix avc_netlink_loop() error caused by nonblocking mode.

Quoted 37 lines · Eamon Walsh
Quoted 19 lines · KaiGai Kohei
Quoted 10 lines · Eamon Walsh

avc_open() creates the netlink socket in nonblocking mode. If the application later takes control of the netlink socket with avc_netlink_acquire_fd() and then calls avc_netlink_loop(), it will fail with EWOULDBLOCK.

To remedy this, remove the O_NONBLOCK flag from the netlink socket at the start of avc_netlink_loop(). Also, with this fix, there is no need for avc_open() to ever create a blocking socket, so change that and update the man page.

Apart from this design is sane, the libselinux allows applications to call avc_netlink_check_nb() directly.
If we call the function although its worker thread calls avc_netlink_loop(), the invocation of avc_netlink_check_nb() can be blocked, because it assumes the internal netlink socket is non-blocking mode.
(Of course, we will not see the matter in most of sane applications.)

Quoted 7 lines

I think a better approach is to put select(2) with zero or infinite timeout just before avc_netlink_receive() calls to check whether the unread message is in the netlink socket, or not.
And the 'blocking' argument of avc_netlink_open() shall be obsoleted, because this design makes nonsense whether the socket has O_NONBLOCK flag, or not.

OK I see your point. How about the following:

libselinux: fix avc_netlink_loop() error caused by nonblocking mode.

avc_open() creates the netlink socket in nonblocking mode. If the application later takes control of the netlink socket with avc_netlink_acquire_fd() and then calls avc_netlink_loop(), it will fail with EWOULDBLOCK.

Quoted 8 lines

To remedy this, remove the O_NONBLOCK flag from the netlink socket at the start of avc_netlink_loop(). Also, with this fix, there is no need for avc_open() to ever create a blocking socket, so change that and update the man page.

-v2: use poll() in avc_netlink_check_nb(). This makes both avc_netlink_loop() and avc_netlink_check_nb() independent of the O_NONBLOCK flag.

It seems to me ok basically.

It is just my preference. Can you move the poll(2) at the head of the avc_netlink_receive() call, like as the attachment? How should I say...it seems to me itchy to change non-blocking mode into blocking mode implicitly at avc_netlink_loop(), although we can specify the mode at creation time (avc_netlink_open()).

Thanks,

Quoted 95 lines

--

  man/man3/avc_netlink_loop.3 |   11 +++--------
  src/avc.c                   |    2 +-
  src/avc_internal.c          |   13 +++++++++++++
  3 files changed, 17 insertions(+), 9 deletions(-)
libselinux/man/man3/avc_netlink_loop.3 +3 -8
index 67df6e4..785be4c 100644
@@ -41,12 +41,9 @@ descriptor is stored internally; use
  .BR avc_netlink_acquire_fd (3)
  to take ownership of it in application code.  The
  .I blocking
-argument specifies whether read operations on the socket will block.
+argument controls whether the O_NONBLOCK flag is set on the socket descriptor.
  .BR avc_open (3)
-calls this function internally, specifying non-blocking behavior (unless
-threading callbacks were explicitly set using the deprecated
-.BR avc_init (3)
-interface, in which case blocking behavior is set).
+calls this function internally, specifying non-blocking behavior.
 
  .B avc_netlink_close
  closes the netlink socket.  This function is called automatically by
@@ -66,9 +63,7 @@ checks the netlink socket for pending messages and processes them.
  Callbacks for policyload and enforcing changes will be called;
  see
  .BR selinux_set_callback (3).
-This function does not block unless
-.BR avc_netlink_open (3)
-specified blocking behavior.
+This function does not block.
 
  .B avc_netlink_loop
  enters a loop blocking on the netlink socket and processing messages as they
libselinux/src/avc.c +1 -1
index 881b915..5c8def0 100644
@@ -222,7 +222,7 @@ int avc_init(const char *prefix,
  		avc_enforcing = rc;
  	}
 
-	rc = avc_netlink_open(avc_using_threads);
+	rc = avc_netlink_open(0);
  	if (rc<  0) {
  		avc_log(SELINUX_ERROR,
  			"%s:  can't open netlink socket: %d (%s)\n",
libselinux/src/avc_internal.c +13 -0
index 8372f52..7a39c61 100644
@@ -15,6 +15,7 @@
  #include<unistd.h>
  #include<fcntl.h>
  #include<string.h>
+#include<poll.h>
  #include<sys/types.h>
  #include<sys/socket.h>
  #include<linux/types.h>
@@ -205,8 +206,18 @@ int avc_netlink_check_nb(void)
  {
  	int rc;
  	char buf[1024] __attribute__ ((aligned));
+	struct pollfd pfd = { fd, POLLIN | POLLPRI, 0 };
 
  	while (1) {
+		rc = poll(&pfd, 1, 0);
+		if (rc == 0)
+			return 0;
+		if (rc<  0) {
+			avc_log(SELINUX_ERROR, "%s:  netlink poll: error %d\n",
+				avc_prefix, errno);
+			return rc;
+		}
+
  		errno = 0;
  		rc = avc_netlink_receive(buf, sizeof(buf));
  		if (rc<  0) {
@@ -233,6 +244,8 @@ void avc_netlink_loop(void)
  	int rc;
  	char buf[1024] __attribute__ ((aligned));
 
+	fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)&  ~O_NONBLOCK);
+
  	while (1) {
  		errno = 0;
  		rc = avc_netlink_receive(buf, sizeof(buf));
Signature · 1 line
KaiGai Kohei <[email protected]>
 libselinux/man/man3/avc_netlink_loop.3 |   11 +++--------
 libselinux/src/avc.c                   |    2 +-
 libselinux/src/avc_internal.c          |   20 +++++++++++++++++---
 3 files changed, 21 insertions(+), 12 deletions(-)
libselinux/man/man3/avc_netlink_loop.3 +3 -8
index 67df6e4..785be4c 100644
@@ -41,12 +41,9 @@ descriptor is stored internally; use
 .BR avc_netlink_acquire_fd (3)
 to take ownership of it in application code.  The
 .I blocking
-argument specifies whether read operations on the socket will block.
+argument controls whether the O_NONBLOCK flag is set on the socket descriptor.
 .BR avc_open (3)
-calls this function internally, specifying non-blocking behavior (unless
-threading callbacks were explicitly set using the deprecated
-.BR avc_init (3)
-interface, in which case blocking behavior is set).
+calls this function internally, specifying non-blocking behavior.
 
 .B avc_netlink_close
 closes the netlink socket.  This function is called automatically by
@@ -66,9 +63,7 @@ checks the netlink socket for pending messages and processes them.
 Callbacks for policyload and enforcing changes will be called;
 see
 .BR selinux_set_callback (3).
-This function does not block unless
-.BR avc_netlink_open (3)
-specified blocking behavior.
+This function does not block.
 
 .B avc_netlink_loop
 enters a loop blocking on the netlink socket and processing messages as they
libselinux/src/avc.c +1 -1
index 881b915..5c8def0 100644
@@ -222,7 +222,7 @@ int avc_init(const char *prefix,
 		avc_enforcing = rc;
 	}
 
-	rc = avc_netlink_open(avc_using_threads);
+	rc = avc_netlink_open(0);
 	if (rc < 0) {
 		avc_log(SELINUX_ERROR,
 			"%s:  can't open netlink socket: %d (%s)\n",
libselinux/src/avc_internal.c +17 -3
index 8372f52..be4c0a3 100644
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <poll.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <linux/types.h>
@@ -92,13 +93,26 @@ void avc_netlink_close(void)
 	close(fd);
 }
 
-static int avc_netlink_receive(char *buf, unsigned buflen)
+static int avc_netlink_receive(char *buf, unsigned buflen, int blocking)
 {
 	int rc;
+	struct pollfd pfd = { fd, POLLIN | POLLPRI, 0 };
 	struct sockaddr_nl nladdr;
 	socklen_t nladdrlen = sizeof nladdr;
 	struct nlmsghdr *nlh = (struct nlmsghdr *)buf;
 
+	rc = poll(&pfd, 1, (blocking ? -1 : 0));
+
+	if (rc == 0 && !blocking) {
+		errno = EWOULDBLOCK;
+		return -1;
+	}
+	else if (rc < 1) {
+		avc_log(SELINUX_ERROR, "%s:  netlink poll: error %d\n",
+			avc_prefix, errno);
+		return rc;
+	}
+
 	rc = recvfrom(fd, buf, buflen, 0, (struct sockaddr *)&nladdr,
 		      &nladdrlen);
 	if (rc < 0)
@@ -208,7 +222,7 @@ int avc_netlink_check_nb(void)
 
 	while (1) {
 		errno = 0;
-		rc = avc_netlink_receive(buf, sizeof(buf));
+		rc = avc_netlink_receive(buf, sizeof(buf), 0);
 		if (rc < 0) {
 			if (errno == EWOULDBLOCK)
 				return 0;
@@ -235,7 +249,7 @@ void avc_netlink_loop(void)
 
 	while (1) {
 		errno = 0;
-		rc = avc_netlink_receive(buf, sizeof(buf));
+		rc = avc_netlink_receive(buf, sizeof(buf), 1);
 		if (rc < 0) {
 			if (errno == 0 || errno == EINTR)
 				continue;
#7 lore raw

Re: [PATCH] libselinux: fix avc_netlink_loop() error caused by nonblocking mode.

Quoted 11 lines · KaiGai Kohei

It seems to me ok basically.

It is just my preference. Can you move the poll(2) at the head of the avc_netlink_receive() call, like as the attachment? How should I say...it seems to me itchy to change non-blocking mode into blocking mode implicitly at avc_netlink_loop(), although we can specify the mode at creation time (avc_netlink_open()).

Thanks,

I have pushed this patch, thanks.

Signature · 8 lines
Eamon Walsh 
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.