From patchwork Tue Apr 28 18:23:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 226946 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1DE7C83004 for ; Tue, 28 Apr 2020 18:26:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89254208E0 for ; Tue, 28 Apr 2020 18:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588098400; bh=xh5jasGP+qlz4q1zVydQmxu/W7eq4W6XizMxpF9rPFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0VND0+igtHSFsOrpR1/s8OMvcyIyaJKDIhSK7QGqyWJwLpeJPuCI0pb54p4ttMDFY T+w8ESiFYFYOHvEeT3H7hk5Ld6ZDgTZllwywKMiqpG1PZa1CbbZW06Sl5VBYxB+XSW yr9gE5+tOXzPMWZumcQBQmrUXXeMGpI1DHJDJvHw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728788AbgD1S0j (ORCPT ); Tue, 28 Apr 2020 14:26:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:38262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728779AbgD1S0h (ORCPT ); Tue, 28 Apr 2020 14:26:37 -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 034C42173E; Tue, 28 Apr 2020 18:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588098397; bh=xh5jasGP+qlz4q1zVydQmxu/W7eq4W6XizMxpF9rPFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a2oXbecdZaYvQOjfInc1oslhOej23y+WEMzPVEq+B3IRgxDwRNu3KaeDFNpfYmurn M6MaRzpjLr+IVqDMN66nqUAtBbKOjxqSEUW4pud5R5Guxj1EloLa15fOUp3iOh1MNj Xv+DFX5hqeERwsQPugeejkcQk3/hEex7fWjsQysc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasily Averin , Andrew Morton , Waiman Long , Davidlohr Bueso , Manfred Spraul , Al Viro , Ingo Molnar , NeilBrown , Peter Oberparleiter , Steven Rostedt , Linus Torvalds , Sasha Levin Subject: [PATCH 5.6 023/167] ipc/util.c: sysvipc_find_ipc() should increase position index Date: Tue, 28 Apr 2020 20:23:19 +0200 Message-Id: <20200428182228.105979287@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200428182225.451225420@linuxfoundation.org> References: <20200428182225.451225420@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vasily Averin [ Upstream commit 89163f93c6f969da5811af5377cc10173583123b ] If seq_file .next function does not change position index, read after some lseek can generate unexpected output. https://bugzilla.kernel.org/show_bug.cgi?id=206283 Signed-off-by: Vasily Averin Signed-off-by: Andrew Morton Acked-by: Waiman Long Cc: Davidlohr Bueso Cc: Manfred Spraul Cc: Al Viro Cc: Ingo Molnar Cc: NeilBrown Cc: Peter Oberparleiter Cc: Steven Rostedt Link: http://lkml.kernel.org/r/b7a20945-e315-8bb0-21e6-3875c14a8494@virtuozzo.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- ipc/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipc/util.c b/ipc/util.c index fe61df53775ac..2d70f25f64b83 100644 --- a/ipc/util.c +++ b/ipc/util.c @@ -764,13 +764,13 @@ static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos, total++; } + *new_pos = pos + 1; if (total >= ids->in_use) return NULL; for (; pos < ipc_mni; pos++) { ipc = idr_find(&ids->ipcs_idr, pos); if (ipc != NULL) { - *new_pos = pos + 1; rcu_read_lock(); ipc_lock_object(ipc); return ipc;