Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1566654ybl; Thu, 22 Aug 2019 17:16:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQ9U6Ut3Z1bCxjfYiZ7qCpwLQQUKa/kfDhE8kh012EN1Zjtgawno8tRgK38JWYRJBlFH1Q X-Received: by 2002:a17:902:7b94:: with SMTP id w20mr1557842pll.227.1566519389847; Thu, 22 Aug 2019 17:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566519389; cv=none; d=google.com; s=arc-20160816; b=InKcvZCzsxbBtDhccX0XnqZnEKkn6/ZNQw9wQvfVpFRU2I1YRDIOKgV9iBfTnHGhId QvW+eGPzcxq30GQb0mg+e0VX5cq2xk9+VyCEx9WjJ7bJNsCj6e6KR/OmkCWutcQomaSZ Wdpj9DUFj1p75M+Wc4CnFYcl3ZwFpbSSdBjSEaBzVgvuE0oPmPJI51Wsk81vA11Uee1r 50gIdtwTx4WA8jUUBHxlcxnasuQhb5acQh6JwuS/ZPjFysTtI0OzzUZEUQ8tUCWJuJO7 RhPX/K/ThWtZbBycZoHyD4QvcCjUwZLYPaURTeyyIfmspQoHb+ht5Jwylat3h0pqfC9W xaSQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6Zpg7OYAdgKM9DmhKn00UgSnZQMZV7KpztTvSOieC1Q=; b=Bhfq4GsUWNVrj+IrLtQ8e7Prdv3HF132OYEhtGQQMY3NgVDiXUtx4uxJs93PJo5yXv oWqG/qyn/Rf5iIAJKoH2rbD8zFlcmDPs6tay+y888LfB6Hgf3ctuhf+zMe5zwhA3hZja KHVfUgtFqPtu6G9gKApzhny6nAs8C3lfJx7kFDkiTiNGJNXh8gNUg5BmJwJoWhEFUblb Ns57HpvDkTev2Ql8T+yIFVVYv6IgXpfj65lO32U3iG9P8XnxoN4/jjfccJoEPUPJYwXD Ku4ZuSJuQp/JZJnvsVWIlC4Otwr8/QRpkUzVH0uOduIq446CqIpOO8aSrH6QPiC8K5a0 pilg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uqynQSxK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si867749pld.69.2019.08.22.17.16.13; Thu, 22 Aug 2019 17:16:29 -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=uqynQSxK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733007AbfHVRS1 (ORCPT + 99 others); Thu, 22 Aug 2019 13:18:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:57584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388846AbfHVRIP (ORCPT ); Thu, 22 Aug 2019 13:08:15 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F72223402; Thu, 22 Aug 2019 17:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493694; bh=5j8eSVDxtdl+CJ7xV2ee7Pj08LtadYXJ6WneXT9Kpf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uqynQSxKdSrnPndUog4JDQMHYth6RLSbR/k7qppL2GjEunhNgsk4SPCKZ+o8OTr+Y aN9jUIA5/rAuxHVirzIFOzViOMiFR6SUq7IzZbjz9Hyzmf848fDj2dKBmDWjoScPpH vFN1LhZjsyGURYdV0KIUlPJQzFMt2ISRrnSPpAzw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: NeilBrown , Sergei Turchanov , Alexander Viro , Markus Elfring , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman Subject: [PATCH 5.2 003/135] seq_file: fix problem when seeking mid-record Date: Thu, 22 Aug 2019 13:05:59 -0400 Message-Id: <20190822170811.13303-4-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore 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(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index abe27ec431766..225bf9239b329 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -119,6 +119,7 @@ static int traverse(struct seq_file *m, loff_t offset) } 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, loff_t offset) } pos += m->count; m->count = 0; - p = m->op->next(m, p, &m->index); if (pos == offset) break; } -- 2.20.1