Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp530202img; Thu, 21 Mar 2019 03:35:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyx0l0KVltSzSL1887WD3pd/z48DTWMKcg9srov0nk4kgC3vQmXkAhV5Hfg9QmUuJfaaE+i X-Received: by 2002:a65:64cc:: with SMTP id t12mr2714976pgv.438.1553164511518; Thu, 21 Mar 2019 03:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553164511; cv=none; d=google.com; s=arc-20160816; b=fFxaey9pdMxyiZ1yNmcTaPoPSzvv4AVHJ0oQ81mhcsjYe0AfoyBc853Sqj6zV1RV/A j3i+3WILHFnxfo9dEHcp+6hYFYXW78z1l9ZolOaPg42zLl9rT7JRK8fS5t0R92SZREF8 8Dncu3uTjp7oLGEUhKmjXiXzpJqFNq4rK5Rp78UeN4dgI4wZ8VsIt+G6uDOREoDfhxfM PIwaa2os8hG48rztedlk2oIR5CJ51jwrMykMTu8S3Z70vgcpNzYWMC/tJRTW6hwldXxC C2P5xEZD/Ryo3jq02PZcGbnGsFoKRYU1diIU7kIKgIDRc6W1+4Hlzz+zPBFK4/HKFk95 S2dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=EGt7wnb0MYHpXiWNM7es/Xx++DTZIMYOZKJImn5VExg=; b=zlOpj+THvpYBfopRZyNsi9n4yIIpiw+7eRG+pNTF/u5uf5RfEz9FL1coPjUc4uD2zO 579uTAx+Jvag5s0gy9r3jg2wtahWmhsx5q37SqmdJdAH1U6q4dRuQfJkBVF98tj7gvzl rRgrawoFRUBwW2i5k6OcW1xj0Bfs320qDlt1UpynWwBJyGWCOgBQogAw85Im0tLJaeqw ZaPray5GKJwAqf+qpnTxkZj10h39OwB/j1O1Hn2L1h5MY3LwZh2rnve9o6H2wV0DpMij sPOkNpxvnfd45JUpTeleKbCc0DPiCEU60iSkk59+kQ/bIyvqQxz/fr2mrdB7wHe6fEwi DfCQ== 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 r11si3888947pga.249.2019.03.21.03.34.53; Thu, 21 Mar 2019 03:35:11 -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 S1728145AbfCUKdx (ORCPT + 99 others); Thu, 21 Mar 2019 06:33:53 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:40405 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727867AbfCUKdw (ORCPT ); Thu, 21 Mar 2019 06:33:52 -0400 Received: by mail-qt1-f195.google.com with SMTP id x12so5962413qts.7 for ; Thu, 21 Mar 2019 03:33:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EGt7wnb0MYHpXiWNM7es/Xx++DTZIMYOZKJImn5VExg=; b=ZvOzThkhsUsc41vWhQ2aUsNThNVXxkTmeIsoGca4v0tc8AzVKKaXdMJdaceKYQsH5d YAG9n1Zh3h5qr0E2rwD/zJFywsMQj1FEBspFb4BgkC/LYHH7szO3k1qZLX2L6/QdYDo7 ivB0u2bVo9yZeVU3i5Fgt68MJ1cZ7jjL8r1J7KcN+hoS1Fao8oifbRyUG1cZmU9GpqcI g3ZLeIkmJH1cVqyaBD9Q8o8gTgkmE94LzdOsbKn66db+HjZRwKq/L71Q66ZRe3nfUztc zwTwj/ceSBorKNloKOMDmnBBmpmPLDZJtDbuxGzJaTpUCBJLInxzV8dGO5LakDCBMFTq Rl4g== X-Gm-Message-State: APjAAAUoRGDFsCOaqCd/fgze0OjECu5cfoCnD4CSyBjCBCnnQxl9QCfZ R1QMWHCTuAn31apONNVNsGQywcHJrFPj7V4nCEM= X-Received: by 2002:a0c:b758:: with SMTP id q24mr2357112qve.149.1553164431110; Thu, 21 Mar 2019 03:33:51 -0700 (PDT) MIME-Version: 1.0 References: <20150115173132.GA7486@mcrowe.com> <20190321104726.3c570c41e5757611a13c23ca@gmail.com> In-Reply-To: <20190321104726.3c570c41e5757611a13c23ca@gmail.com> From: Arnd Bergmann Date: Thu, 21 Mar 2019 11:33:33 +0100 Message-ID: Subject: Re: kmsg: lseek errors confuse glibc's dprintf To: Alexander Sverdlin Cc: Mike Crowe , Linux Kernel Mailing List , Andrew Morton , Kay Sievers , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 21, 2019 at 10:47 AM Alexander Sverdlin wrote: > > Hello Mike and all, > > On Thu, 15 Jan 2015 17:31:32 +0000 > Mike Crowe wrote: > > > glibc's dprintf implementation does not work correctly with /dev/kmsg file > > descriptors because glibc treats receiving EBADF and EINVAL from lseek when > > trying to determine the current file position as errors. See > > https://sourceware.org/bugzilla/show_bug.cgi?id=17830 > > we need to conclude on this issue. This is a real bug which is ignored > for 4 years now. Mike, would you like to re-send a formal patch? > I can do it as well, preserving a link to your original patch/report. > In case you'd like to post it yourself, I can be a tester and/or > provide a reproducer. The patch needs to be rebased because of the changed file location. I would also suggest adding a "Cc: stable@kernel.org" tag so it will get backported into stable kernels. > > >>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. > > > > For maximum compatibility it seems that success should be returned but > > given Kay's new seek interface perhaps this isn't helpful. > > > > This patch ensures that such a seek succeeds: > > > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > > index 02d6b6d..b3ff6f0 100644 > > --- a/kernel/printk/printk.c > > +++ b/kernel/printk/printk.c > > @@ -693,7 +693,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) > > loff_t ret = 0; > > > > if (!user) > > - return -EBADF; > > + return (whence == SEEK_CUR) ? 0 : -EBADF; > > if (offset) > > return -ESPIPE; > > > > @@ -718,6 +718,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 requesting the > > + * current file position. */ > > + ret = 0; > > + break; > > default: > > ret = -EINVAL; > > } > > > > (although it could be argued that the !user case should return -ESPIPE > > rather than EBADF since the file descriptor _is_ valid.) I don't think the !user case can ever be hit, I would just leave that to return -BADF and not touch it. > > @@ -718,6 +718,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; > > } > > > > Either makes dprintf work, but is either the right solution? I'd vote for -ESPIPE, for consistency with the offset!=0 case, but etiher one is fine with me here. Arnd