public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kmsg: properly handle concurrent non-blocking read() from /proc/kmsg
@ 2012-07-03 18:17 Kay Sievers
  2012-07-04  6:22 ` Jan Beulich
  0 siblings, 1 reply; 2+ messages in thread
From: Kay Sievers @ 2012-07-03 18:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Yuanhan Liu, Jan Beulich

From: Kay Sievers <kay@vrfy.org>
Subject: kmsg: properly handle concurrent non-blocking read() from /proc/kmsg

The /proc/kmsg read() interface is internally simply wired up to a sequence
of syslog() syscalls, which might are racy between their checks and actions,
regarding concurrency.

In the (very uncommon) case of concurrent readers of /dev/kmsg, relying on
usual O_NONBLOCK behavior, the recently introduced mutex might block an
O_NONBLOCK reader in read(), when poll() returns for it, but another process
has already read the data in the meantime. We've seen that while running
artificial test setups and tools that "fight" about /proc/kmsg data.

This restores the original /proc/kmsg behavior, where in case of concurrent
read()s, poll() might wake up but the read() syscall will just return 0 to
the caller, while another process has "stolen" the data.

This is in the general case not the expected behavior, but it is the exact
same one, that can easily be triggered with a 3.4 kernel, and some tools
might just rely on it.

The mutex is not needed, the original integrity issue which introduced it,
is in the meantime covered by:
  "fill buffer with more than a single message for SYSLOG_ACTION_READ"
  116e90b23f74d303e8d607c7a7d54f60f14ab9f2

Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Cc: Jan Beulich <JBeulich@suse.com>
Signed-off-by: Kay Sievers <kay@vrfy.org>
---
 kernel/printk.c |    9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1019,7 +1019,6 @@ int do_syslog(int type, char __user *buf
 {
 	bool clear = false;
 	static int saved_console_loglevel = -1;
-	static DEFINE_MUTEX(syslog_mutex);
 	int error;
 
 	error = check_syslog_permissions(type, from_file);
@@ -1046,17 +1045,11 @@ int do_syslog(int type, char __user *buf
 			error = -EFAULT;
 			goto out;
 		}
-		error = mutex_lock_interruptible(&syslog_mutex);
-		if (error)
-			goto out;
 		error = wait_event_interruptible(log_wait,
 						 syslog_seq != log_next_seq);
-		if (error) {
-			mutex_unlock(&syslog_mutex);
+		if (error)
 			goto out;
-		}
 		error = syslog_print(buf, len);
-		mutex_unlock(&syslog_mutex);
 		break;
 	/* Read/clear last kernel messages */
 	case SYSLOG_ACTION_READ_CLEAR:



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] kmsg: properly handle concurrent non-blocking read() from /proc/kmsg
  2012-07-03 18:17 [PATCH] kmsg: properly handle concurrent non-blocking read() from /proc/kmsg Kay Sievers
@ 2012-07-04  6:22 ` Jan Beulich
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Beulich @ 2012-07-04  6:22 UTC (permalink / raw)
  To: gregkh, kay; +Cc: yuanhan.liu, linux-kernel

>>> Kay Sievers <kay@vrfy.org> 07/03/12 8:17 PM >>>
>From: Kay Sievers <kay@vrfy.org>
>Subject: kmsg: properly handle concurrent non-blocking read() from /proc/kmsg
>
>The /proc/kmsg read() interface is internally simply wired up to a sequence
>of syslog() syscalls, which might are racy between their checks and actions,
>regarding concurrency.
>
>In the (very uncommon) case of concurrent readers of /dev/kmsg, relying on
>usual O_NONBLOCK behavior, the recently introduced mutex might block an
>O_NONBLOCK reader in read(), when poll() returns for it, but another process
>has already read the data in the meantime. We've seen that while running
>artificial test setups and tools that "fight" about /proc/kmsg data.
>
>This restores the original /proc/kmsg behavior, where in case of concurrent
>read()s, poll() might wake up but the read() syscall will just return 0 to
>the caller, while another process has "stolen" the data.
>
>This is in the general case not the expected behavior, but it is the exact
>same one, that can easily be triggered with a 3.4 kernel, and some tools
>might just rely on it.
>
>The mutex is not needed, the original integrity issue which introduced it,
>is in the meantime covered by:
>"fill buffer with more than a single message for SYSLOG_ACTION_READ"
  >116e90b23f74d303e8d607c7a7d54f60f14ab9f2
>
>Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
>Cc: Jan Beulich <JBeulich@suse.com>
>Signed-off-by: Kay Sievers <kay@vrfy.org>

This being a revert of all but a single change of
4a77a5a06ec66ed05199b301e7c25f42f979afdc, which I had suggested to
be reverted anyway:

Acked-by: Jan Beulich <jbeulich@suse.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-04  6:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-03 18:17 [PATCH] kmsg: properly handle concurrent non-blocking read() from /proc/kmsg Kay Sievers
2012-07-04  6:22 ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox