[PATCH 66/73] policycoreutils -- Fix infinite loop i watch code Fix infinite loop i watch code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


   This patch looks good to me. acked.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9x334ACgkQrlYvE4MpobM5NACePnnhHdm3xIxpVBhVfqn2GvkE
32oAoJwLrbTC4e7N4okk6dwTvF8A6QAl
=tlkk
-----END PGP SIGNATURE-----
>From 9eca8fe0d121ceadf41496375a9aac36a85dbf9c Mon Sep 17 00:00:00 2001
From: Laurent Bigonville <bigon@xxxxxxxxxx>
Date: Mon, 26 Mar 2012 17:31:25 +0200
Subject: [PATCH 66/73] policycoreutils -- Fix infinite loop i watch code

Hi,

This patch seems old, and I /think/ has already been proposed once.

From: Manoj Srivastava <srivasta@xxxxxxxxxx>
Date: Wed, 14 Oct 2009 02:03:28 -0500
Subject: Fix infinite loop i watch code

    [topic--utmp-watch-fix]: Fix infinite loop i watch code

    With kernel 2.6.31, restorecond uses 99% of my CPU.

    This is because removing and readding the watch on utmp triggers inotify to
    return an IN_IGNORED event for the old watch descriptor.  If the watch gets
    allocated the same wd when it is readded, then restorecond thinks that utmp
    has changed, so removes and readds the watch again, potentially looping.

    With kernel <= 2.6.30, this never happened, because the kernel didn't reuse
    watch descriptors.  So the IN_IGNORED event comes with a wd that is no
    longer in use, and gets ignored.  But kernel 2.6.31 reuses the same watch
    descriptor.

    This patch fixes that by ignoring inotify events whose only bit set is
    IN_IGNORED.

    Note: it is not clear to me why it is necessary to remove and readd the
    watch in the first place.

    Patch by Martin Orr.

    Signed-off-by: Martin Orr <martin@xxxxxxxxxxxxxx>
    Signed-off-by: Manoj Srivastava <srivasta@xxxxxxxxxx>

Signed-off-by: Eric Paris <eparis@xxxxxxxxxx>
---
 policycoreutils/restorecond/watch.c |   28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/policycoreutils/restorecond/watch.c b/policycoreutils/restorecond/watch.c
index 6a833c3..9a45cba 100644
--- a/policycoreutils/restorecond/watch.c
+++ b/policycoreutils/restorecond/watch.c
@@ -186,20 +186,22 @@ int watch(int fd, const char *watch_file)
 			printf("wd=%d mask=%u cookie=%u len=%u\n",
 			       event->wd, event->mask,
 			       event->cookie, event->len);
-		if (event->wd == master_wd)
-			read_config(fd, watch_file);
-		else {
-			switch (utmpwatcher_handle(fd, event->wd)) {
-			case -1:	/* Message was not for utmpwatcher */
-				if (event->len)
-					watch_list_find(event->wd, event->name);
-				break;
-			case 1:	/* utmp has changed need to reload */
+		if (event->mask & ~IN_IGNORED) {
+			if (event->wd == master_wd)
 				read_config(fd, watch_file);
-				break;
-
-			default:	/* No users logged in or out */
-				break;
+			else {
+				switch (utmpwatcher_handle(fd, event->wd)) {
+				case -1:	/* Message was not for utmpwatcher */
+					if (event->len)
+						watch_list_find(event->wd, event->name);
+					break;
+				case 1:	/* utmp has changed need to reload */
+					read_config(fd, watch_file);
+					break;
+
+				default:	/* No users logged in or out */
+					break;
+				}
 			}
 		}
 
-- 
1.7.9.3


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux