Received: by 10.223.185.116 with SMTP id b49csp1021867wrg; Wed, 21 Feb 2018 10:42:49 -0800 (PST) X-Google-Smtp-Source: AH8x226MWWgy9B4pISGT0/m/SyzhMxwUwN4YasYgEM/nGn5mk6cVg8kjFDTnmMDRawe2XESqSWJ0 X-Received: by 2002:a17:902:7883:: with SMTP id q3-v6mr3940440pll.361.1519238569243; Wed, 21 Feb 2018 10:42:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238569; cv=none; d=google.com; s=arc-20160816; b=oKaKJZohAiEMoZt/ZFI4Y/bIK2b5nejLr7vy1UgUXrTFEIObQjGCiA0fFoyE4h9gcQ zksggyBBN8kWDkButJ43bbM6sAsQnKsIZrSqsvvsKPz6wrEIxHFyWYP3IA9+GWhKdw2B cIMcI4jy3VcbsELKzKxM64m1QMl7HSlrJZlRGwuO3aColmpVJRpUYxzHUt7x/GRM5jtX EMqf4/nUdfhsf6ngv+RJRuMUu/XW6nF3C2wl5q9lt2H1JIBDB6aUlN60Sr2MbTf0nkmB H6QQjCbuwrlw9jGW3lsKAmArc71p+xPqKOZUFCMKrXmI7NzxZupOfSJUDRggD1Yx+2AT 0PBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=KymspB6CWKflwrGr9q1k0fcFoPV4maxk1JUY0i5+c4U=; b=X9XxxPSPJRHXV42IcS7LW0Eewxn94OofivoJiNM87BVy17W83wYphsQwJBo5kIZ5Gf qhn6EF5IhRAQSyTRJ0C0VFMZROzJXXakc/B67nGfg7IuNf5wIxoLHZ7nT12CJ6Ur3Mb+ Nl/hqk0PCyvcUiYiz6YX60+K//r8EfiROM6+5zn/GS2kbHhv7bdF44HRe/Ie6AiO5StO ldDDQ/AmmvBzNzcp4rOP3ZJjGvSWNQjg2tBWwuxe8hfKMEEWSWcwJ1wyXfTg45u/L5wn a5Xd6yFxaOANXSPfEe0c6FGIdhZ7yILdRh1mdxqA04RE9Z3JsabgU5h1F8tEt9DP7wWU u5QQ== 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 g4si1120615pgr.797.2018.02.21.10.42.34; Wed, 21 Feb 2018 10:42:49 -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 S965800AbeBUN0G (ORCPT + 99 others); Wed, 21 Feb 2018 08:26:06 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44696 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936355AbeBUNLT (ORCPT ); Wed, 21 Feb 2018 08:11:19 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 466892C; Wed, 21 Feb 2018 13:11:18 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rich Felker , Miklos Szeredi , Al Viro Subject: [PATCH 4.15 124/163] seq_file: fix incomplete reset on read from zero offset Date: Wed, 21 Feb 2018 13:49:13 +0100 Message-Id: <20180221124537.001351159@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Miklos Szeredi commit cf5eebae2cd28d37581507668605f4d23cd7218d upstream. 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 Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- 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)) {