Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp115900ybl; Thu, 22 Aug 2019 21:03:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2U5647cMh/qEfAbZYymKjHBtX2u3L/usGzAqyoTiXZI77NiGzhe2HvaTHQDsh009e0yYV X-Received: by 2002:a17:902:6842:: with SMTP id f2mr2459449pln.39.1566533010388; Thu, 22 Aug 2019 21:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566533010; cv=none; d=google.com; s=arc-20160816; b=fy6tYEwyeUfWa5JhMQudXpxQj/gWvDKpy6Q2yUox96QKovyuJYzxysx0Y+QE1M9bxT 4iK9xAIeM5DNXJPYvZdD5Rr/2BytPffFtE5Sm3qfpo6OkFxxjyr/RQg65MEDRtpTFFjT T/13yX9mr99R5pwMECrHvWJ0i50DsLMLM3mL+6w6wKp0fqwWQxV2d3+hRi6cBzKIG1yR Ahdvu4A8Rm0PzkCe2xj+xgQjwHTq6aag945ARqUQ7NDjJZjsAXdzaq21J/YkuK8m8D3W j/8km75RLv0NYWSQMbQh5eCudNrvNH6/QSNsttYVc/lEo+PKHpuOJIACX+aGMaOnMLRj /4WA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m1wgZ8NTFNrMbQvuXY7iQd/Ipww9JBNIdlSpTFaRw6E=; b=VK4S5rXs92oDmn1WtZYOql4NyvqQI03Yhnf17d6U7vJG6pGMZIEjeJItI6/HhQ3Ns5 C2hl6auipKmJFjFz4FB1EwYgQksZLxj2kMMV1w1uEMpx6OYGbxWmcnAeAXXwdZAjYApY aDQCNyUTvQitPg1qxTf4/VIdfYG9QLYONPF/yPdyEHBJv7Kl6X2YO0YQsWSMG95/yH6O V7Ck2VoElxv1ZD7ACneVfWLvjuQoTATKzqkjherSl/0PL1ZSYjikfasT0XZTMQ6P684j lggaS05+7GxXu/5eyLpsQ5hLTeZVGzSQPsyOgKrDLszRs8GuMinq/aiaWdK6efsSqILu wneQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pU2OAP3k; 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 n123si956370pgn.151.2019.08.22.21.03.14; Thu, 22 Aug 2019 21:03:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b=pU2OAP3k; 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 S2404118AbfHVRdS (ORCPT + 99 others); Thu, 22 Aug 2019 13:33:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:48860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404440AbfHVRZa (ORCPT ); Thu, 22 Aug 2019 13:25:30 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62C64206DD; Thu, 22 Aug 2019 17:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494729; bh=q4onTBR6zS2Y3N1AAVKfOzKAZCjaWZP3uQTJPBHi15M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pU2OAP3kCWu6IJ7jAsyhoNxaEkeG3/RgFYhem1A+jzzNppCcMZcWXD/8uoj+pro2J FS8iTtit83iEByNcowGebCbZed0eZCf+aQ3vHqa+UUJ2oxbh8kp5a8njV0FgBvf7i2 bk5pVVRxKjp56VjrQRlU80NDvypKDWuIq/vRTwwA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Sergei Turchanov , Alexander Viro , Markus Elfring , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 02/85] seq_file: fix problem when seeking mid-record Date: Thu, 22 Aug 2019 10:18:35 -0700 Message-Id: <20190822171731.107842321@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171731.012687054@linuxfoundation.org> References: <20190822171731.012687054@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: NeilBrown commit 6a2aeab59e97101b4001bac84388fc49a992f87e upstream. If you use lseek or similar (e.g. pread) to access a location in a seq_file file that is within a record, rather than at a record boundary, then the first read will return the remainder of the record, and the second read will return the whole of that same record (instead of the next record). When seeking to a record boundary, the next record is correctly returned. This bug was introduced by a recent patch (identified below). Before that patch, seq_read() would increment m->index when the last of the buffer was returned (m->count == 0). After that patch, we rely on ->next to increment m->index after filling the buffer - but there was one place where that didn't happen. Link: https://lkml.kernel.org/lkml/877e7xl029.fsf@notabene.neil.brown.name/ Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") Signed-off-by: NeilBrown Reported-by: Sergei Turchanov Tested-by: Sergei Turchanov Cc: Alexander Viro Cc: Markus Elfring Cc: [4.19+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/seq_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -119,6 +119,7 @@ static int traverse(struct seq_file *m, } if (seq_has_overflowed(m)) goto Eoverflow; + p = m->op->next(m, p, &m->index); if (pos + m->count > offset) { m->from = offset - pos; m->count -= m->from; @@ -126,7 +127,6 @@ static int traverse(struct seq_file *m, } pos += m->count; m->count = 0; - p = m->op->next(m, p, &m->index); if (pos == offset) break; }