Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3882839pxv; Mon, 28 Jun 2021 15:36:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP0BQtj0CIb5p7xf4hUhMB0AHKrfVHFRuNS7KS02NIdyjIpuVMuFm9IB/kQlPJ49gvgh+u X-Received: by 2002:a6b:5902:: with SMTP id n2mr1425661iob.20.1624919790538; Mon, 28 Jun 2021 15:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624919790; cv=none; d=google.com; s=arc-20160816; b=bQ30YXzGctq3svqyn55Flp31/Hfv2YHXUG35jryOWgTPiip/+SDRFMpJ7Q3Gyw2eAX RUuiUgJBF8BGYm++1fugGxPpNd4YkQEX8HN0XcdUdU1h0oUVd0cYe7Kk0arE3Gat9L6P yUMJuthaluq3Qqmch/P+PcqSI8M8r56FCGuDYExezBMwyDw2Rdj/8oW/y9YFuniurhHr P281jieasWvucGrTRvG9MXgfBLarkJw13uQtANmsT34JF2DrTFUKQwtaxGHDvHDk5Gqx xABQevoTCKwOAmPimhI668i3LzHOS7+uWuHV5BAbxSWPq/YXzgCCShKHsNl4xkL5R0Ib fEGw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EpVTa2mrvlpNi9z64BDQhpt1bObwWQXudm65ccFuuOQ=; b=y1q4/DqYavYmtjeBd3lbaEi2wCsRcbRSV/h8KEbY+XVktpufpE6SiSiJFUnKKdFinF EuVKYq0cLQ8zsvnvw4ipS6sO6nVWSe7le2kxnw1jlzArdp2VV1HXBnyOGbPHW0Dq00gn FEctgeSL7nZmmrzzRGy88cbiSZEXWnMH2+F8VqNMDRvfqiM+btFcY4ZZzG+quWitL/rD n3GVZliuIigKkc9MzX4cJCsYCuYl2fCjfBtJ9jm/G2laWV0EOUkSLh8lofPR0AN/Bt4q cGJ/+QRyD/guykJAoSWwGD5wTE0lBMYkA0IsSHJkEvfypJayoFIzLY0kdtc/wba0C7Qu qGCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hEiCipb2; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si21659119ilu.88.2021.06.28.15.36.16; Mon, 28 Jun 2021 15:36:30 -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=k20201202 header.b=hEiCipb2; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237558AbhF1P22 (ORCPT + 99 others); Mon, 28 Jun 2021 11:28:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:37106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235715AbhF1PEN (ORCPT ); Mon, 28 Jun 2021 11:04:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8129361CE8; Mon, 28 Jun 2021 14:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891392; bh=80zjMMzXKplIKYNBqWtEYGuxkeFc2XDJqFc2Ge/+TCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEiCipb2rJ+/DGPJTJnJ6LHATu77e7ATdzzwPLcJa6VTo3+ZGbKSSbQEmr89pxZOq MkzkqADC8Pjms+2fzP2p2NddHmvJ6JWOdT+tT0cYCOIxYHDTo8hZMpF2/aqI/faiCu kziHd7x+9WU4siNtrFYX1rl0ptqVGOATxbHLzhWurOaSqL4PlFQi/W9T7Km6MzXyMY nR9wSSwFO4pxu4IdBz0Bta6uT+GA89Ad7CvDZb4vkFg0ssqINtT1tid+skZSpGV1fB pwKuwramd0WwMSK9YEshun2VLF9yWJb17lA4RmkAn2OX/9rbc+BvwcvEjQdFUm2gYg dkxRafEg4YMsQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Skripkin , syzbot+5134cdf021c4ed5aaa5f@syzkaller.appspotmail.com, =?UTF-8?q?H=C3=A5kon=20Bugge?= , Santosh Shilimkar , "David S . Miller" , Sasha Levin Subject: [PATCH 4.4 16/57] net: rds: fix memory leak in rds_recvmsg Date: Mon, 28 Jun 2021 10:42:15 -0400 Message-Id: <20210628144256.34524-17-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144256.34524-1-sashal@kernel.org> References: <20210628144256.34524-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.4.274-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.4.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:42+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 49bfcbfd989a8f1f23e705759a6bb099de2cff9f ] Syzbot reported memory leak in rds. The problem was in unputted refcount in case of error. int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, int msg_flags) { ... if (!rds_next_incoming(rs, &inc)) { ... } After this "if" inc refcount incremented and if (rds_cmsg_recv(inc, msg, rs)) { ret = -EFAULT; goto out; } ... out: return ret; } in case of rds_cmsg_recv() fail the refcount won't be decremented. And it's easy to see from ftrace log, that rds_inc_addref() don't have rds_inc_put() pair in rds_recvmsg() after rds_cmsg_recv() 1) | rds_recvmsg() { 1) 3.721 us | rds_inc_addref(); 1) 3.853 us | rds_message_inc_copy_to_user(); 1) + 10.395 us | rds_cmsg_recv(); 1) + 34.260 us | } Fixes: bdbe6fbc6a2f ("RDS: recv.c") Reported-and-tested-by: syzbot+5134cdf021c4ed5aaa5f@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin Reviewed-by: HÃ¥kon Bugge Acked-by: Santosh Shilimkar Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/rds/recv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/rds/recv.c b/net/rds/recv.c index 9bf812509e0e..1ff4bc3237f0 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c @@ -482,7 +482,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, if (rds_cmsg_recv(inc, msg)) { ret = -EFAULT; - goto out; + break; } rds_stats_inc(s_recv_delivered); -- 2.30.2