Received: by 10.223.164.202 with SMTP id h10csp1496878wrb; Wed, 8 Nov 2017 05:17:24 -0800 (PST) X-Google-Smtp-Source: ABhQp+S4x6+2PSoJlpT69+2iglDFbw1HvLWLcnMOK7mjIuPM94nxVAYHGTFCrHJUnaDvNdnuARMn X-Received: by 10.99.129.73 with SMTP id t70mr456141pgd.227.1510147043913; Wed, 08 Nov 2017 05:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510147043; cv=none; d=google.com; s=arc-20160816; b=nQxGiSxQ7NCW5a0WO1baOLM/fFpHRgGF3kh/vzRDBDDh7dOh6+xppZ49JqIYnJ0f66 htBFQUG6YWFYobO/aShF5syHYMfH7VzIqCBS2UNMMH3aJfVQGFG8vXb+uaKoNsSPGfhj y9FJTZhUzrVwOCcwuVmG/O5mqgyCwHQUIqUKbYajuU1lyR0BDmCpss2+l7AFsG0jR0b0 AkzAM+XSjTlwr9CM07n5weUcrlduA2EVrmeyivIWZ8EcYHPLlrwdOJgxxUuyjrKaOfqB qZuSgK6H0FnzTwTuMiI5/n2vSSueZs+I1lUYDATa0ZqwhMs1jBxEELC0J+V+0pPxba90 R7PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:arc-authentication-results; bh=epzZTrKN0eCtW6nrhFyLhBPrGmO2HAB5lTUpF1tyRx0=; b=vycHSTPsF0P16Z0NonGfNI24augfcjalg/r3PofP3opU506Qu24aGaoSBKj7tflIAP LCise5qz9HQkWr8Qabven/25HFmj97LkahwBHsx4pdo0HESv9VSNxuqtx+9hNjeiH4JJ JlzCo85H1J2fklKPGpgECUx/DZ/FvOtdsFL0JuGHnSK0WAkPs46ddQhQMixW61o0LqQn YwAikXlkkqn70yEmKU1kOEeoSyOIWAO2e50KGMTykbvrMmW7CkfMqGAgQ4zHaY6LOe++ YvO6LeXxOH5ZWWN7ZCKebWO/aS5tIXkUbE5HCR0EdNVom/psi5ZmUGGcGYbJz7y/nhpX yxkg== 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 l3si3859877pld.174.2017.11.08.05.17.11; Wed, 08 Nov 2017 05:17:23 -0800 (PST) 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 S1752467AbdKHNQe (ORCPT + 82 others); Wed, 8 Nov 2017 08:16:34 -0500 Received: from port70.net ([81.7.13.123]:56850 "EHLO port70.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751955AbdKHNQc (ORCPT ); Wed, 8 Nov 2017 08:16:32 -0500 X-Greylist: delayed 385 seconds by postgrey-1.27 at vger.kernel.org; Wed, 08 Nov 2017 08:16:31 EST Received: by port70.net (Postfix, from userid 1002) id 80193ABEC092; Wed, 8 Nov 2017 14:10:05 +0100 (CET) Date: Wed, 8 Nov 2017 14:10:05 +0100 From: Szabolcs Nagy To: Miklos Szeredi Cc: Al Viro , Tomasz Majchrzak , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, musl@lists.openwall.com, Rich Felker Subject: Re: [(resend)] seq_file: reset iterator to first record for zero offset Message-ID: <20171108131005.GA15263@port70.net> Mail-Followup-To: Miklos Szeredi , Al Viro , Tomasz Majchrzak , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, musl@lists.openwall.com, Rich Felker References: <20161219113800.GE27207@veci.piliscsaba.szeredi.hu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161219113800.GE27207@veci.piliscsaba.szeredi.hu> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Miklos Szeredi [2016-12-19 12:38:00 +0100]: > Al, > > Can you please take (or NACK) this patch please? > > Thanks, > Miklos > --- > From: Tomasz Majchrzak > Date: Tue, 29 Nov 2016 15:18:20 +0100 > > If kernfs file is empty on a first read, successive read operations > using the same file descriptor will return no data, even when data is > available. Default kernfs 'seq_next' implementation advances iterator > position even when next object is not there. Kernfs 'seq_start' for > following requests will not return iterator as position is already on > the second object. > > This defect doesn't allow to monitor badblocks sysfs files from MD raid. > They are initially empty but if data appears at some stage, userspace is > not able to read it. > > Signed-off-by: Tomasz Majchrzak > Signed-off-by: Miklos Szeredi > --- this patch broke userspace abi: commit e522751d605d99a81508e58390a8f51ee96fb662 Author: Tomasz Majchrzak AuthorDate: 2016-11-29 15:18:20 +0100 Commit: Al Viro CommitDate: 2016-12-22 23:03:06 -0500 seq_file: reset iterator to first record for zero offset reported in may at: https://bugzilla.kernel.org/show_bug.cgi?id=195697 read(fd,buf,0) on sysfs/procfs changes the behaviour of the next read: the next read reads the first line twice. same issue with readv() with a 0 length buffer. test code: #include #include #include int main(int argc, char* argv[]) { char buf1[512] = {0}; char buf2[512] = {0}; int fd; fd = open("/proc/mounts", O_RDONLY); if (read(fd, buf1, 0) < 0) return 1; if (read(fd, buf1, 512) < 0) return 1; lseek(fd, 0, SEEK_SET); if (read(fd, buf2, 512) < 0) return 1; // buf1 should be the same as buf2, // the first 512 bytes of /proc/mounts buf1[511]=buf2[511]='\n'; write(1, "# buf1:\n", 8); write(1, buf1, 512); // prints the first line twice write(1, "# buf2:\n", 8); write(1, buf2, 512); return memcmp(buf1, buf2, 512) != 0; } stdio in musl libc can use readv with 0 length buffer in some cases, and various tools use stdio to read these synthetic filesystems so this is observable regression between linux v4.9 and v4.10 (i think musl can avoid the 0 length buffer in stdio, but the linux behaviour is still incorrect. in general readv/writev could have more posix conform behaviour on sysfs/procfs, currently they don't behave as atomic fs operations which is surprising: writev with several buffers behaves as if several independent write syscalls were made instead of one, which can cause issues when users do 'echo 12 >/proc/foo' and writev is used in the stdio implementation) > fs/seq_file.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > -- > To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > > --- a/fs/seq_file.c > +++ b/fs/seq_file.c > @@ -190,6 +190,13 @@ ssize_t seq_read(struct file *file, char > */ > m->version = file->f_version; > > + /* > + * if request is to read from zero offset, reset iterator to first > + * record as it might have been already advanced by previous requests > + */ > + if (*ppos == 0) > + m->index = 0; > + > /* Don't assume *ppos is where we left it */ > if (unlikely(*ppos != m->read_pos)) { > while ((err = traverse(m, *ppos)) == -EAGAIN) From 1583989805028781162@xxx Mon Nov 13 21:59:54 +0000 2017 X-GM-THRID: 1583805290382379451 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread