From patchwork Tue Feb 6 10:27:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10202725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7B3E86020F for ; Tue, 6 Feb 2018 10:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DEA1289D2 for ; Tue, 6 Feb 2018 10:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61CE028A33; Tue, 6 Feb 2018 10:27:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06B3E289F0 for ; Tue, 6 Feb 2018 10:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752715AbeBFK1i (ORCPT ); Tue, 6 Feb 2018 05:27:38 -0500 Received: from mail-wr0-f171.google.com ([209.85.128.171]:42227 "EHLO mail-wr0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752650AbeBFK1b (ORCPT ); Tue, 6 Feb 2018 05:27:31 -0500 Received: by mail-wr0-f171.google.com with SMTP id 41so1307173wrc.9 for ; Tue, 06 Feb 2018 02:27:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=pZnH1ITiOaGXqkvUJPMVmVHLEaGHUCSeWZGSwJKqlOM=; b=fPqYpvnNlOSV1f5xd47teY7U6Iu/xyojtcs8dZZk0EjRtaeoZ69IbH0s5Z3ylGSo7W dhnMWUmL2Uk6SYoEL/m7vLqLBI0VdocwQnoxWXa8JLTFGVlxR1wXam1SH4mEkPNEhuPE l4UI4UjP0N57GJvON31AGXdzj6OMRD8msDvDs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=pZnH1ITiOaGXqkvUJPMVmVHLEaGHUCSeWZGSwJKqlOM=; b=lgClEecEddm7tR3OHtwzwaknp0Pun4dXE2nPp3os/+BLxwOoS8BAxc1wU9FvFRtyf3 BtcuYM8YrxuTmRk87/uFM0oJgSGisSNi0HC54PiKtOzzopKcFhhTFXEDWcHwIobCNZy1 wFiwLst1LnLvB9axTMeN0DKZGfrWflU1m+3mJprRqP7E4RuZQZcLppe77eimKxOJcGf2 22HJALqCIV8uxwrASVTy7RqAEQaB+TNytDkJRaosbyLNJyaQQlengbTZ17IkOehGW1Yb sgqvZ5DR0pFrtXzRZ07ujHg+SNARaIs9EKDR/gJu0C/HxqqKmEdRxQLOyzj3DxODNS4t gSzw== X-Gm-Message-State: APf1xPDiZxpoxgLmbZgQaVhL6n07OPOucz6vjCF7zQ5AHhyEMxWvtofM +Fj04othvgil9BwEjMeC4eq1GkGt X-Google-Smtp-Source: AH8x226drpUZExUx5FK0Av9lGZ5vltCPIy1RMp3M+CWjb2eE4GKdbFiuSQxbAUruRUjmUb48ieckaA== X-Received: by 10.223.199.194 with SMTP id y2mr1563785wrg.170.1517912850745; Tue, 06 Feb 2018 02:27:30 -0800 (PST) Received: from veci.piliscsaba.redhat.com (C2B0E321.catv.pool.telekom.hu. [194.176.227.33]) by smtp.gmail.com with ESMTPSA id q1sm6098279wrf.40.2018.02.06.02.27.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Feb 2018 02:27:29 -0800 (PST) Date: Tue, 6 Feb 2018 11:27:27 +0100 From: Miklos Szeredi To: Al Viro Cc: Rich Felker , Szabolcs Nagy , Tomasz Majchrzak , linux-fsdevel , linux-kernel Subject: [PATCH] seq_file: fix incomplete reset on read from zero offset Message-ID: <20180206102727.GB19579@veci.piliscsaba.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When resetting iterator on a zero offset we need to discard any data already in the buffer (count), and private state of the iterator (version). For example this bug results in first line being repeated in /proc/mounts if doing a zero size read before a non-zero size read. Reported-by: Rich Felker Signed-off-by: Miklos Szeredi Fixes: e522751d605d ("seq_file: reset iterator to first record for zero offset") Cc: # v4.10 --- fs/seq_file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -181,8 +181,11 @@ ssize_t seq_read(struct file *file, char * 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) + if (*ppos == 0) { m->index = 0; + m->version = 0; + m->count = 0; + } /* Don't assume *ppos is where we left it */ if (unlikely(*ppos != m->read_pos)) {