Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3837891pxv; Mon, 28 Jun 2021 14:18:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUJsdeMnq6qCrgwzX2CxMkCLC2w/j7SBgB1PmZj5wsY/JPvE2/Dop/H6dL2x1KuMNIpQKZ X-Received: by 2002:a92:db4b:: with SMTP id w11mr190799ilq.194.1624915095632; Mon, 28 Jun 2021 14:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624915095; cv=none; d=google.com; s=arc-20160816; b=fm5wvnWouPJlCSbo0RjO/gT85zDHt/snD9Ep8l3HFiDc3mVlUGi/BPpWMDVbSVP7MG ZwToHQvn0Xe3WtScV7W5UKaALoTKzY+4S9ZWcBa8xKV7mCIHC4Q8AJJthAoDmCyUz+ja GVsLY5jBFBHPjM5e2Vi9+Iz3a5tq/QqB7pT2eCgEk4yPDUHgDhjQZiMoUadpWVF56PDd Sknk0zkCDNU9GpFCH+ERABJj+kLT2Dp+7yVRUiGwZQcVuwI80fJvQjD3yPFQIbmSBoAs 87XG0PHyu25ZgdYWHUfekfsdAD9ziRjt7xpa6BeNOjN4Mvf2eVpLM4k3wkd+2Jn1pqhv JS6g== 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=pmg9aGM+OO1NlC9aSTif0B1IbtyNQdao3ajR1Bn8uqQ=; b=Fg4uwVHPv/mtI5vSPX6YLMsa+Y6GUUVF5nqgsoZora+JErHwTQ5YAfc1DvnMrREU94 l20X3sg0OLp7mYWJ6jJ05pGfk0ifbKBh80+UqjoQuQHG2ZIyww9FWMRzZPoE4dct3zR9 ejHubQENlYC3O4MSyvD9e2xRnYv+W2pRBVBg/6IAeoISWIMlLCGxzNxRJSUE4NCYQ3t8 pfxl20LsPUIkbpkcDo6840HLTafgk2PsDBY+4ogxUrg6APrdqqDoBgg8eqsDWOt/tGeO mUf9f6Kv9RCp2U7OD3aDfgFvwm2j19b8CRmvcY3piX8cSps4p16Y9GUc2evm2r3McKRz +UJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rmact7jc; 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 d3si14719699ilg.84.2021.06.28.14.17.59; Mon, 28 Jun 2021 14:18:15 -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=rmact7jc; 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 S237723AbhF1PUI (ORCPT + 99 others); Mon, 28 Jun 2021 11:20:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:60294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236995AbhF1O4d (ORCPT ); Mon, 28 Jun 2021 10:56:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5CF0D61CC5; Mon, 28 Jun 2021 14:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891223; bh=RVPtrFADfjza2zULrp6PbGAxR2RcXL0gYJlsZQbCXow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rmact7jcI7piuFO+Oo8Da7BQgdpE+A15I+x0vH/a89yGZvqGbvmPiFQuOQvXWpMi4 +XXkOrDIcfI0s4VZ7kasyvfKcav6x8Wls1HsLEH8NSNSOsbWmoyHmyOzcdGWnXx9om u3MC85i0LBXbVsQJzKEpiz8zxW0G5Ig2PrINlhEoqawn4OKSTvHQQPo/x8XgZugMUZ liyL3EboELiC8VP1xeFnKKziVqBCkO8nQgsSNZWBtre+XEVCa0KWSqRuYUrpCFJTCA UhvPs5KPFsQIxPVs43Iwf/hedy2ryOCFgHAdbKQwhB5o97g8swWiuJn6usQRBNKxVt Awpg7EOCN+Zvw== 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.9 20/71] net: rds: fix memory leak in rds_recvmsg Date: Mon, 28 Jun 2021 10:39:12 -0400 Message-Id: <20210628144003.34260-21-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144003.34260-1-sashal@kernel.org> References: <20210628144003.34260-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.9.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.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:39+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 488a198be3e1..4bd307e31b40 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c @@ -596,7 +596,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, if (rds_cmsg_recv(inc, msg, rs)) { ret = -EFAULT; - goto out; + break; } rds_stats_inc(s_recv_delivered); -- 2.30.2