Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3631686pxb; Mon, 24 Jan 2022 13:59:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVG0PX/is2XsS2OT4qnwwfR5yKHvylW5dmxkOlt4LeM3HcdM7931tyAB6SQGPvFdNeew9t X-Received: by 2002:a17:90b:1801:: with SMTP id lw1mr320810pjb.215.1643061586455; Mon, 24 Jan 2022 13:59:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061586; cv=none; d=google.com; s=arc-20160816; b=jeEsgE6AWum0yDTDJ5UFYxEQDgktABnqnv19wwQBl6YSoCm+WleI+QVxrA1RWztKU/ 1NUIksAuvGiG7oFxwMGVx/jW7AuygC7/uyU3mNyXkjax21RpbRm6ZWdS5oI+XhCpvcGR zunWs1/XhNaPruefiTZCUZ8Sb8akD+1S9MWIBVuC2xAXfLmjTVvX/zoPG7TNJYEYHbIP LlCgvjfwdlTdo3tySP0VYfj4EitEuCrLqMJhw64U0SSK89razsOMdjAGYZBP5cQss5rH vQ/xE6knh0Nj80pHM5kbt1DTo50A00cxrh4GnzZNIBROKsA4bCmXBHr2thjJcIph9YB5 w5rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r94VYZ8CWCStxOKIs5VRnUay/24FSiOkmdEirp+MgaE=; b=oLy8P4BIeUWdNl6ce0LGce5HdtztPfwZKxXNliNDX9krya9Gwn5xbZCpKrglAzCMjc 9GE8yIlmw+obGqP/+7oZ92AF/qLBdpISMNLbi9vquL+eJGTZnN74VQaElMS62MMi2gRf VjoZX/ESk5QHNcIbKB6lCgPLyNfYvHpTOYjBFRQ7Mk3ZOsUsMXcSkClLpmFffREF4Ltv Hz7aExjfo69fRjT8NKEXLHwRcpXxHJmyas7XX4gJnAjYF/mwlM+vvxmYTD4FuZ497REq Nx7Bi7Dwl87X5BhUIIeY6q+V5RfEgGUci47PBNWud7/sydb+EGFz8ieVvjpTgWxNkxh/ IlSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gl+S+cVi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y62si10322236pgd.360.2022.01.24.13.59.33; Mon, 24 Jan 2022 13:59:46 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=gl+S+cVi; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379537AbiAXVtc (ORCPT + 99 others); Mon, 24 Jan 2022 16:49:32 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:36992 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1448888AbiAXVOJ (ORCPT ); Mon, 24 Jan 2022 16:14:09 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F1B9C6149E; Mon, 24 Jan 2022 21:14:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9AC2C340E7; Mon, 24 Jan 2022 21:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058844; bh=pwnwnU/LAdzSlH5GmWQH3agJIXJJWSc13ZnYoVB68hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gl+S+cVirc9DvgeO3U+5UpmJb/vZoN9Y+dLpiN8EMKftFBj3bkDotNbb7x3x9G6nJ lLme0AHQt7pjhfzUOJqB9ggoQafqMT+nO9eDqwReI2SPLibTbRYP0aKZgpTLBvh5IB OG7lyN8sUDqHtqxCw93hAtOSgOrdXLAeumbkNdF0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Morton , Michal Hocko , Paolo Abeni , Mat Martineau , "David S. Miller" , Sasha Levin , syzbot+bc9e2d2dbcb347dd215a@syzkaller.appspotmail.com Subject: [PATCH 5.16 0421/1039] mptcp: Check reclaim amount before reducing allocation Date: Mon, 24 Jan 2022 19:36:50 +0100 Message-Id: <20220124184139.452884444@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mat Martineau [ Upstream commit 269bda9e7da48eafb599d01c96199caa2f7547e5 ] syzbot found a page counter underflow that was triggered by MPTCP's reclaim code: page_counter underflow: -4294964789 nr_pages=4294967295 WARNING: CPU: 2 PID: 3785 at mm/page_counter.c:56 page_counter_cancel+0xcf/0xe0 mm/page_counter.c:56 Modules linked in: CPU: 2 PID: 3785 Comm: kworker/2:6 Not tainted 5.16.0-rc1-syzkaller #0 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014 Workqueue: events mptcp_worker RIP: 0010:page_counter_cancel+0xcf/0xe0 mm/page_counter.c:56 Code: c7 04 24 00 00 00 00 45 31 f6 eb 97 e8 2a 2b b5 ff 4c 89 ea 48 89 ee 48 c7 c7 00 9e b8 89 c6 05 a0 c1 ba 0b 01 e8 95 e4 4b 07 <0f> 0b eb a8 4c 89 e7 e8 25 5a fb ff eb c7 0f 1f 00 41 56 41 55 49 RSP: 0018:ffffc90002d4f918 EFLAGS: 00010082 RAX: 0000000000000000 RBX: ffff88806a494120 RCX: 0000000000000000 RDX: ffff8880688c41c0 RSI: ffffffff815e8f28 RDI: fffff520005a9f15 RBP: ffffffff000009cb R08: 0000000000000000 R09: 0000000000000000 R10: ffffffff815e2cfe R11: 0000000000000000 R12: ffff88806a494120 R13: 00000000ffffffff R14: 0000000000000000 R15: 0000000000000001 FS: 0000000000000000(0000) GS:ffff88802cc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b2de21000 CR3: 000000005ad59000 CR4: 0000000000150ee0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: page_counter_uncharge+0x2e/0x60 mm/page_counter.c:160 drain_stock+0xc1/0x180 mm/memcontrol.c:2219 refill_stock+0x139/0x2f0 mm/memcontrol.c:2271 __sk_mem_reduce_allocated+0x24d/0x550 net/core/sock.c:2945 __mptcp_rmem_reclaim net/mptcp/protocol.c:167 [inline] __mptcp_mem_reclaim_partial+0x124/0x410 net/mptcp/protocol.c:975 mptcp_mem_reclaim_partial net/mptcp/protocol.c:982 [inline] mptcp_alloc_tx_skb net/mptcp/protocol.c:1212 [inline] mptcp_sendmsg_frag+0x18c6/0x2190 net/mptcp/protocol.c:1279 __mptcp_push_pending+0x232/0x720 net/mptcp/protocol.c:1545 mptcp_release_cb+0xfe/0x200 net/mptcp/protocol.c:2975 release_sock+0xb4/0x1b0 net/core/sock.c:3306 mptcp_worker+0x51e/0xc10 net/mptcp/protocol.c:2443 process_one_work+0x9b2/0x1690 kernel/workqueue.c:2298 worker_thread+0x658/0x11f0 kernel/workqueue.c:2445 kthread+0x405/0x4f0 kernel/kthread.c:327 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 __mptcp_mem_reclaim_partial() could call __mptcp_rmem_reclaim() with a negative value, which passed that negative value to __sk_mem_reduce_allocated() and triggered the splat above. Check for a reclaim amount that is positive and large enough for __mptcp_rmem_reclaim() to actually adjust rmem_fwd_alloc (much like the sk_mem_reclaim_partial() code the function is based on). v2: Use '>' instead of '>=', since SK_MEM_QUANTUM - 1 would get right-shifted into nothing by __mptcp_rmem_reclaim. Fixes: 6511882cdd82 ("mptcp: allocate fwd memory separately on the rx and tx path") Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/252 Reported-and-tested-by: syzbot+bc9e2d2dbcb347dd215a@syzkaller.appspotmail.com Cc: Andrew Morton Cc: Michal Hocko Acked-by: Paolo Abeni Signed-off-by: Mat Martineau Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/mptcp/protocol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 54613f5b75217..0cd55e4c30fab 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -972,7 +972,9 @@ static void __mptcp_mem_reclaim_partial(struct sock *sk) lockdep_assert_held_once(&sk->sk_lock.slock); - __mptcp_rmem_reclaim(sk, reclaimable - 1); + if (reclaimable > SK_MEM_QUANTUM) + __mptcp_rmem_reclaim(sk, reclaimable - 1); + sk_mem_reclaim_partial(sk); } -- 2.34.1