lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Sun, 24 Mar 2019 10:27:13 +0000
From:   Mike Crowe <>
Cc:     Mike Crowe <>, Kay Sievers <>,
        Arnd Bergmann <>,
        Alexander Sverdlin <>,
Subject: [PATCH] kmsg: Return -ESPIPE rather than EBADF from llseek(SEEK_CUR)

glibc's dprintf implementation tries to determine the current file position
by calling lseek(fd, 0, SEEK_CUR). Unfortunately it treats receiving EINVAL
as an error. See

>From what I can tell prior to Kay Sievers printk record commit
e11fea92e13fb91c50bacca799a6131c81929986, calling lseek(fd, 0, SEEK_CUR)
with such a file descriptor would not return an error.

Prior to Kay's change, Arnd Bergmann's commit
6038f373a3dc1f1c26496e60b6c40b164716f07e seemed to go to some lengths to
preserve the successful return code rather than returning (the perhaps more
logical) -ESPIPE.

glibc is happy with either a successful return or -ESPIPE. It seems that
the consensus is to return -ESPIPE in this situation.

Alexander Sverdlin supplied this test case:
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <fcntl.h>

 int main(int argc, char **argv)
         return dprintf(open("/dev/kmsg", O_WRONLY), "\n") < 0;

Signed-off-by: Mike Crowe <>
Cc: Arnd Bergmann <>
Tested-by: Alexander Sverdlin <>
Fixes: e11fea92e1 ("kmsg: export printk records to the /dev/kmsg interface")
 kernel/printk/printk.c | 5 +++++
 1 file changed, 5 insertions(+)

Originally posted as . Thanks to
Alexander for waking this up and helping to test the updated fix.

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 02ca827b8fac..4f047b13162c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -945,6 +945,11 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
 		user->idx = log_next_idx;
 		user->seq = log_next_seq;
+	case SEEK_CUR:
+		/* For compatibility with userspace expecting SEEK_CUR
+		 * to not yield EINVAL. */
+		ret = -ESPIPE;
+		break;
 		ret = -EINVAL;

Powered by blists - more mailing lists