Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1393222ybz; Thu, 16 Apr 2020 08:23:29 -0700 (PDT) X-Google-Smtp-Source: APiQypI7kSTPv/hh0KJMNrg7nalzBHovue6vn3pbBnDMX4bt6n4hfrgNU3W7zeRxmLWxPWklWKbO X-Received: by 2002:a05:6402:793:: with SMTP id d19mr30197855edy.106.1587050609419; Thu, 16 Apr 2020 08:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587050609; cv=none; d=google.com; s=arc-20160816; b=hemHQ8b+8LXblCWaFb7SeCLFZzibdleRBfP7JIa7fUJMyFqKuA1JvyLHwYbRLZvxtW pAqsSBQBH4yhhgXdZQsogiiqh4VHJiZexjOkL5tayIqTdmHYkVIqEwHEqEGlHy08qzlr tmhN7KB7FpaVrjThzVbrh/GRT4WLZw362xKggQyxATmf6yaik+1D4rqqxh3q14nBU9NX d5TckVVGwrzIFGMZXmQd4+e7GKOKVVaMxcs9ly/Y4ZN5TdZ65H3r1e/n/NH+gfo9cnLX qAFnqURJtrj2bTMWUCNX3p0DZR6Y0MBhHkfGmUzGx5+Rna3f0PmQGBHFFBcskHazxLsn w6FQ== 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=k4wpzXCJQiorGeJObkYAYMb6Io55VITLbI83EIT7zAQ=; b=q4Y6Svfnf2LelnRdRkaSnOv3wr6nVnAtN89J9tElV5yBNbgBD6Ukmul9PiQoCf536t A6X2dQcqBj0f/dRGiTlJxT6yzLlw8wpp4e2Dv1v0EhbJCFZuXCvtQabi3ovtgQC0LmUy /mtVjD3cJJe7HIu15GEF43OWvn8Yb/m7yRMtotU/ikY/eC2/bnhIR7JA48jtyZHo6XEn TGCr+an2oEFpaqJIDKb3BlNxTEImuuV2A31vaK5pHWtWyv8jVWoueMmzWbcm44RBx/95 /8kDs7ueKM3zXOyQcgeoQf9GDqeqbbcWKXyKMbVfRGv5Xtm4EYHiH+WZ6w+3oY5xziBm sB6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1WuGoGEg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si1579424ejt.101.2020.04.16.08.23.04; Thu, 16 Apr 2020 08:23:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1WuGoGEg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729218AbgDPPVI (ORCPT + 99 others); Thu, 16 Apr 2020 11:21:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:32924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2898637AbgDPNq5 (ORCPT ); Thu, 16 Apr 2020 09:46:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 D3421208E4; Thu, 16 Apr 2020 13:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587044816; bh=/BTERr8ntuoVM+oROY3RpI5yVZsGtjKuXRPEP0DY5B8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1WuGoGEgRTvfLmEDvvZlNSqIy5Dp0jBkBCWWS0+xEYqdFJJW5kAOjhy5uYJjs/Vsq NnAZ5BWwc8lEdK/hQJfLoxUBLwi3F6L9RUxrSVn59aad/pmEYpDeyXSVmCftUcb8yV Z6SB7rhEpQ/Kc1DKDJXZiq+DBYNLRpeWEKwOkpBo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasily Averin , Kees Cook Subject: [PATCH 5.4 113/232] pstore: pstore_ftrace_seq_next should increase position index Date: Thu, 16 Apr 2020 15:23:27 +0200 Message-Id: <20200416131329.272025766@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131316.640996080@linuxfoundation.org> References: <20200416131316.640996080@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: Vasily Averin commit 6c871b7314dde9ab64f20de8f5aa3d01be4518e8 upstream. 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" /proc/swaps output was fixed recently, however there are lot of other affected files, and one of them is related to pstore subsystem. If .next function does not change position index, following .show function will repeat output related to current position index. There are at least 2 related problems: - read after lseek beyond end of file, described above by NeilBrown "dd if= bs=1000 skip=1" will generate whole last list - read after lseek on in middle of last line will output expected rest of last line but then repeat whole last line once again. If .show() function generates multy-line output (like pstore_ftrace_seq_show() does ?) following bash script cycles endlessly $ q=;while read -r r;do echo "$((++q)) $r";done < AFFECTED_FILE Unfortunately I'm not familiar enough to pstore subsystem and was unable to find affected pstore-related file on my test node. If .next function does not change position index, following .show function will repeat output related to current position index. Cc: stable@vger.kernel.org Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code ...") Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283 Signed-off-by: Vasily Averin Link: https://lore.kernel.org/r/4e49830d-4c88-0171-ee24-1ee540028dad@virtuozzo.com [kees: with robustness tweak from Joel Fernandes ] Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- fs/pstore/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -87,11 +87,11 @@ static void *pstore_ftrace_seq_next(stru struct pstore_private *ps = s->private; struct pstore_ftrace_seq_data *data = v; + (*pos)++; data->off += REC_SIZE; if (data->off + REC_SIZE > ps->total_size) return NULL; - (*pos)++; return data; } @@ -101,6 +101,9 @@ static int pstore_ftrace_seq_show(struct struct pstore_ftrace_seq_data *data = v; struct pstore_ftrace_record *rec; + if (!data) + return 0; + rec = (struct pstore_ftrace_record *)(ps->record->buf + data->off); seq_printf(s, "CPU:%d ts:%llu %08lx %08lx %ps <- %pS\n",