Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp2239690img; Sun, 24 Mar 2019 03:30:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVwDN+MMdexifZ0V+bSbylQfxjPsruKaLLKhSo6GYOIt2GKt8j0FMzAKF77hVQEkGZN2I+ X-Received: by 2002:a62:1b84:: with SMTP id b126mr18074116pfb.225.1553423429521; Sun, 24 Mar 2019 03:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553423429; cv=none; d=google.com; s=arc-20160816; b=ixOSThF9Y8BpzBArk58B20R57Npbd0Q8FzPRnLLyooO7DfGqpVEgjH6JU2b2QSp9Ak f6eDP7/XrR6CpkIjKGYpguQtNzXg20D1Oi0cRce4ayj9cEBHtI4zNe0Ebcfi52CKM57i 67WjQc6D1vOk/7tqUCrfhqcIQMgWLdkqULwVJPOESDd98MjJNImuQqjZyD7oJ3hCRlhr ukPxJ3LdAIeDjpXdMocgkfcEix/tYMsOW1zPe/P/TkdK5wa0XrjAtX53IQnn4Wn5OgmC 6jbtRTcl6yE3zMlgbA/GPyf7vGIzBvSkwiChrxB8qLNphRV9glpAftSZUnkHXi/LRyDM c5ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=isRKuXYlOctuUomUunmX3e3l+f+5s5heuf5jtrjefYQ=; b=Us58hh2L0hpqHI9+4f69x6KfxGBUvS2PVv62xPMaW0Cjz5PDVrjVaEfJV2Xk5WbOu4 KuGZXyDl1Zie4k7Du3cKysY86/L+caJ+r1XTcQUC/rmyKTmEe6MI9GVx9/EnWmRjONj/ JhtWRZamwz6dTIAYBa1mJO5AkZLapU+PwdckayAbwYuI1sySwFoViJE4KTg++cJJ35Bb r2k4j8pIBJ0DmIQnFNPXX/tiDgA1g6wEvKRGDAykbyJSSvizNcEHgUISS8LadeyYSpXN 9IqXqaki9v8vi49agUlK5S2unfXMvC+C0kpWUcDaaCtFcpAmC1CS6p94oQ9Q1HglMucl DfrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si3263525plo.98.2019.03.24.03.30.14; Sun, 24 Mar 2019 03:30:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728686AbfCXK2P (ORCPT + 99 others); Sun, 24 Mar 2019 06:28:15 -0400 Received: from avasout02.plus.net ([212.159.14.17]:47283 "EHLO avasout02.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbfCXK2P (ORCPT ); Sun, 24 Mar 2019 06:28:15 -0400 Received: from deneb ([80.229.24.9]) by smtp with ESMTP id 80MMh60E72SW580MNhM3SG; Sun, 24 Mar 2019 10:28:13 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=NtavjPVJ c=1 sm=1 tr=0 a=E/9URZZQ5L3bK/voZ0g0HQ==:117 a=E/9URZZQ5L3bK/voZ0g0HQ==:17 a=NTGMnVQrEZIA:10 a=CCpqsmhAAAAA:8 a=-An2I_7KAAAA:8 a=9qxNCY_qAAAA:8 a=VwQbUJbxAAAA:8 a=D19gQVrFAAAA:8 a=w-YdG8ML7ShXMl4_PY4A:9 a=ul9cdbp4aOFLsgKbc677:22 a=Sq34B_EcNBM9_nrAYB9S:22 a=A2X48xt2e1hG9NJDz63Y:22 a=AjGcO6oz07-iQ99wixmX:22 a=W4TVW4IDbPiebHqcZpNg:22 Received: from mac by deneb with local (Exim 4.89) (envelope-from ) id 1h80ML-0001xW-Mk; Sun, 24 Mar 2019 10:28:09 +0000 From: Mike Crowe To: linux-kernel@vger.kernel.org Cc: Mike Crowe , Kay Sievers , Arnd Bergmann , Alexander Sverdlin , stable@vger.kernel.org Subject: [PATCH] kmsg: Return -ESPIPE rather than EBADF from llseek(SEEK_CUR) Date: Sun, 24 Mar 2019 10:27:13 +0000 Message-Id: <20190324102712.1488-1-mac@mcrowe.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfJl/CbTQc6m3M9qqf2LC9OSlcDhslkxIQU+lrsy3VpN2QmPF5yAQrfmdAL1uVVSiMq/3FkTlEOZTMBN5P6643y9Fjz4RwGO38TyBWYFNhYl1e1YlBIoG 5NFrtdcr2xXiwgj9c5SmXRFwGr7zBNowkE8WwawjIPFMX9B95pFplnAw Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 https://sourceware.org/bugzilla/show_bug.cgi?id=17830 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: --8<-- #define _GNU_SOURCE #include #include int main(int argc, char **argv) { return dprintf(open("/dev/kmsg", O_WRONLY), "\n") < 0; } -->8-- Signed-off-by: Mike Crowe Cc: Arnd Bergmann Tested-by: Alexander Sverdlin Cc: stable@vger.kernel.org Fixes: e11fea92e1 ("kmsg: export printk records to the /dev/kmsg interface") --- kernel/printk/printk.c | 5 +++++ 1 file changed, 5 insertions(+) Originally posted as https://lkml.org/lkml/2015/1/15/575 . 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; break; + case SEEK_CUR: + /* For compatibility with userspace expecting SEEK_CUR + * to not yield EINVAL. */ + ret = -ESPIPE; + break; default: ret = -EINVAL; } -- 2.20.1