From patchwork Fri Jan 31 06:13:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11359209 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C6D7713A4 for ; Fri, 31 Jan 2020 06:13:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9450622522 for ; Fri, 31 Jan 2020 06:13:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="HBgPnME3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9450622522 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E24B6B0517; Fri, 31 Jan 2020 01:13:41 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 71B3B6B0519; Fri, 31 Jan 2020 01:13:41 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 547346B051A; Fri, 31 Jan 2020 01:13:41 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id 3A3736B0517 for ; Fri, 31 Jan 2020 01:13:41 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E43EF180AD804 for ; Fri, 31 Jan 2020 06:13:40 +0000 (UTC) X-FDA: 76436913000.25.anger65_201a9b9f64b2f X-Spam-Summary: 2,0,0,9da8391a24b5a43c,d41d8cd98f00b204,akpm@linux-foundation.org,:akpm@linux-foundation.org:hughd@google.com:jannh@google.com:keescook@chromium.org::mm-commits@vger.kernel.org:torvalds@linux-foundation.org:viro@zeniv.linux.org.uk:vvs@virtuozzo.com,RULES_HIT:41:355:379:800:960:967:973:988:989:1260:1263:1345:1359:1381:1431:1437:1534:1542:1711:1730:1747:1777:1792:1801:2198:2199:2393:2525:2553:2559:2564:2682:2685:2693:2859:2898:2902:2907:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3653:3865:3866:3867:3868:3870:3871:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6261:6653:7576:7903:8603:8957:8985:9025:9121:9545:9707:10004:11026:11257:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12698:12737:12783:12986:13146:13184:13229:13230:13846:14181:14721:14849:21067:21080:21451:21627:21740:21939:21990:30012:30054:30070:30090,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0 ,MSF:not X-HE-Tag: anger65_201a9b9f64b2f X-Filterd-Recvd-Size: 3661 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Fri, 31 Jan 2020 06:13:40 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (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 9F6272173E; Fri, 31 Jan 2020 06:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580451219; bh=83wkJTEy+jfQkyxfhaDsa2KpvkFrSWUHKlWkpSyHzRc=; h=Date:From:To:Subject:In-Reply-To:From; b=HBgPnME3YvEx+toiIndjvhWhYePlt7o82wm6/GJf+qQGr6DfM+oSYDqaeftguf1C/ 7765NtMIr0KuDSXfRQsGsqpB8ossUVlspyPutquccDJJSxd3uiFfz8pzBWm5bIAWU0 w0IpsGYzOwDtdExPwmKjaIDHl6lzcvLtoy6RJHqY= Date: Thu, 30 Jan 2020 22:13:39 -0800 From: Andrew Morton To: akpm@linux-foundation.org, hughd@google.com, jannh@google.com, keescook@chromium.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, vvs@virtuozzo.com Subject: [patch 046/118] mm/swapfile.c: swap_next should increase position index Message-ID: <20200131061339.vdpByFCaP%akpm@linux-foundation.org> In-Reply-To: <20200130221021.5f0211c56346d5485af07923@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Vasily Averin Subject: mm/swapfile.c: swap_next should increase position index If seq_file .next fuction does not change position index, read after some lseek can generate unexpected output. In Aug 2018 NeilBrown noticed commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") "Some ->next functions do not increment *pos when they return NULL... Note that such ->next functions are buggy and should be fixed. A simple demonstration is dd if=/proc/swaps bs=1000 skip=1 Choose any block size larger than the size of /proc/swaps. This will always show the whole last line of /proc/swaps" Described problem is still actual. If you make lseek into middle of last output line following read will output end of last line and whole last line once again. $ dd if=/proc/swaps bs=1 # usual output Filename Type Size Used Priority /dev/dm-0 partition 4194812 97536 -2 104+0 records in 104+0 records out 104 bytes copied $ dd if=/proc/swaps bs=40 skip=1 # last line was generated twice dd: /proc/swaps: cannot skip to specified offset v/dm-0 partition 4194812 97536 -2 /dev/dm-0 partition 4194812 97536 -2 3+1 records in 3+1 records out 131 bytes copied https://bugzilla.kernel.org/show_bug.cgi?id=206283 Link: http://lkml.kernel.org/r/bd8cfd7b-ac95-9b91-f9e7-e8438bd5047d@virtuozzo.com Signed-off-by: Vasily Averin Reviewed-by: Andrew Morton Cc: Jann Horn Cc: Alexander Viro Cc: Kees Cook Cc: Hugh Dickins Signed-off-by: Andrew Morton --- mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/swapfile.c~swap_next-should-increase-position-index +++ a/mm/swapfile.c @@ -2737,10 +2737,10 @@ static void *swap_next(struct seq_file * else type = si->type + 1; + ++(*pos); for (; (si = swap_type_to_swap_info(type)); type++) { if (!(si->flags & SWP_USED) || !si->swap_map) continue; - ++*pos; return si; }