Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4025029ybv; Tue, 25 Feb 2020 11:41:01 -0800 (PST) X-Google-Smtp-Source: APXvYqw4782AlZS+Oo1t2vu2pJiiPw4ARS/z7cI3LA6rBTh2/7imSaFLYYKAcHsxyjhGDO3WGuAu X-Received: by 2002:aca:5194:: with SMTP id f142mr433724oib.100.1582659660927; Tue, 25 Feb 2020 11:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582659660; cv=none; d=google.com; s=arc-20160816; b=JJqQt32ZAQw3CNCxT1YZ/DT3fTa8S7OeK+/vt1Ryi/jQrOs0p7BJsJOAcdGd+qYXSl MUh3T6VTnOcLGUj9JEtCYhXD3wKLM1eU7MHl5nNrrF5tdzYiT8ef7wKU5AL76x6lW23R vBd2TbSX38VS3XSSi/Plbkr9wC16K8nCxXVcfgRadVfMbLDfmq8jWhUQD+ti25ilVbnt N327Szz6tYeGTiZL+Vj/QcGiu/I/zys6QcYK9h63BwrZcx0+3OSSLX4KnymeaaKQlOy0 e0vKxnm+cCagWFprorHWYuxhgNj74rqb3XG+Zkf5hMZ4/V+FPyBxPjxGk3ycdTt+P+e4 2x6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=0uZBykAXAO6jD5DASmZ5tKSqeRVuomezEv1o1XMOkAw=; b=MvLeX+l9wDD/l8MScLr0X/q+tFwrbXBBC2zFn/5MnAUDBfrF7ElBg+3y0WSCrI849V TpdLFZdCtawWSOMNVLCEXKYxx1sHoS/NNqm1WTzJv4AYFPSuHuxDvFPXfpWW4T7A8Cvg vUualdpomdjfzUdd0RWzzq2qjOREqzBAeH399+gGTzVf8Oc+EWLSwUKUO9XgvYiix7Ta +UBdO2uI8554a0l7FExorkT4fmmABzEZHGSRm/EZNj1F/kKWTJJXQZmC+499A9T3mAfP OLsrQP4vYe3GA2yU25+r7Tw0A6bcSNYeJy2X1E4+WuH1Cpj7vIXNMkV2yl5sQ8UiGb2L 8Zxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OIpufyJe; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si65269oiq.162.2020.02.25.11.40.48; Tue, 25 Feb 2020 11:41:00 -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; dkim=pass header.i=@chromium.org header.s=google header.b=OIpufyJe; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730857AbgBYTjv (ORCPT + 99 others); Tue, 25 Feb 2020 14:39:51 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:54593 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728162AbgBYTju (ORCPT ); Tue, 25 Feb 2020 14:39:50 -0500 Received: by mail-pj1-f65.google.com with SMTP id dw13so152589pjb.4 for ; Tue, 25 Feb 2020 11:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0uZBykAXAO6jD5DASmZ5tKSqeRVuomezEv1o1XMOkAw=; b=OIpufyJefzUuIE7EA+vuCdCBPFeaGA+AMgAzJCqQxV/f7sEdIWzaqMl7kL2+83hCgS hQtguyMbdtvRAi0gwq8uh4N+z60MLiNwyVSBuxL+q5v2Fy/6skR+l3LTBvpr0kTuIdvx MW3pAjX8d1AQxA9asqm59YyFka0LDCMVWROEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0uZBykAXAO6jD5DASmZ5tKSqeRVuomezEv1o1XMOkAw=; b=Ou7Nmr8FlbN5/4QR/Tk/ffnpvzZK4tCX0jzZbc0bhnUmtUHT9g7YPmmSPXEQQiyAC7 1zy0IbFwiiAFLS8PgkZXkbGuRZbFriVmbthk6rvpd8eF131ZL6rm+FIK32FaZt0tsWgp uqL/87ZcVBeq5QpOjFBj9oVhaLrWzms/1V3y2M7YEuBIg/hZMLBA81ubpHKATZvJH6WP lhrHkMZAqOcRAkufqf4TLvWOLDkEIdNk6gjp/fy+a7cFuKWpEuFkOApraPTTow10OS/8 64FY3NDNmM4uQyM3xV7MVvErSQNF2K/bRVOKBrcKjHuwhgcCr33jWfqLjQOZxn77YhNr pdzg== X-Gm-Message-State: APjAAAUIEmD5wklBEgZiFYyRxMA5+8257b1v6xTj24evLAeQzXC3Jh/H yAX9/josmjTZYRVLDe70vGpyEQ== X-Received: by 2002:a17:90a:98d:: with SMTP id 13mr694690pjo.102.1582659589946; Tue, 25 Feb 2020 11:39:49 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y5sm18562579pfr.169.2020.02.25.11.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 11:39:49 -0800 (PST) Date: Tue, 25 Feb 2020 11:39:48 -0800 From: Kees Cook To: Vasily Averin , joelaf@google.com Cc: linux-kernel@vger.kernel.org, Anton Vorontsov , Colin Cross , Tony Luck Subject: Re: [PATCH v2] pstore: pstore_ftrace_seq_next should increase position index Message-ID: <202002251136.3816A79E@keescook> References: <4e49830d-4c88-0171-ee24-1ee540028dad@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4e49830d-4c88-0171-ee24-1ee540028dad@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [merged threads] On Tue, Feb 25, 2020 at 11:11:20AM +0300, Vasily Averin wrote: > 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 > --- > fs/pstore/inode.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c > index 7fbe8f0..ea8799b 100644 > --- a/fs/pstore/inode.c > +++ b/fs/pstore/inode.c > @@ -87,11 +87,11 @@ static void *pstore_ftrace_seq_next(struct seq_file *s, void *v, loff_t *pos) > 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; > } > > -- > 1.8.3.1 > I think this make sense, but I figured I'd check with Joel first. Does this look sane for how ftrace will merge records? -- Kees Cook