Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3777451pxv; Mon, 28 Jun 2021 12:36:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/EBKjq2DOS5hL8/xxaWOZs7kSSFrZhjeyzf/gehQ/V0ZhwdNkqjsL9Gb/l0j2LW24055p X-Received: by 2002:a05:6e02:1748:: with SMTP id y8mr19766837ill.234.1624908991274; Mon, 28 Jun 2021 12:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624908991; cv=none; d=google.com; s=arc-20160816; b=Krt1RwnGy8tachbsQf6U8nRTb1yRdvUtaxvLYdG3OpFyoRaZq9WWOBrAvS+83gRhQc kkzqpX994abk78p5jLHxs0THa3wQu+UngPdIUdmdbPH5zxrxjgVB5g6LPduJ4nTOWmru I1CbEeqgjZYlDQEZrIl/Zciw1o7hejOxRrv09YEJmw6Epe9E63WvIxg138LHXQIkycwE qVn4rMtNMvRy8PnMLybQLyq15IhLg0EWtRFtd/1+7ou/x8yiNDOaOdoLaAHU7Nu0CGt2 yE9FaZdZgw0RrZV49Wfyg2X5tg0QRYdyWPV2UxHFPdF0rwJliZYKsDDBwm3n0yWMR3WK ujTw== 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=RPTP5qI7RgMAOysySFf17leHBFFy/VryJ/Vn4e96XE4=; b=YnkppAknEWDbNk0ouEFn8REeJ8tZbB1b77fVsD1BqVX3M80aGDPhoVDU5Wbl9/CLps ZPcSLAYIFR5xyIhuCPNkEWEF+VZeDJUnJk2UGzVGmNdcH6VxjkKsZxuvhSHkW1WAmzHZ CqyV+6gZ4AhBaZBDoavNNT50ooY5o29pCIqE4EUcTYItwg5MTnMmET94h94bVIRBYa+T 5Zi+lzGYCSCc+PmDLhYqcFSpw/PNyjFN0EeBD7M/G4XRO61OCUvqmlJhAOwUj83dJ1Sv YlMaqhPb41+kpTpj5/FbgQB5f4RAzuTJqk726ATG2kggtWgu+D2tdBM0JO9b6o+Hb6Y3 uVsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KMEA3Nud; 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 f10si17778173jag.106.2021.06.28.12.36.17; Mon, 28 Jun 2021 12:36:31 -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=KMEA3Nud; 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 S232047AbhF1O5T (ORCPT + 99 others); Mon, 28 Jun 2021 10:57:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:51692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234748AbhF1OmE (ORCPT ); Mon, 28 Jun 2021 10:42:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3094361CCA; Mon, 28 Jun 2021 14:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890813; bh=303Y9u18xTpqWbTEYGa8hsuqC3zXRn/9rMN8GwPyrn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMEA3NudRCjK13syMzQdbB4JYWN7jRV/yhbF78OPezb+TRiVl2iJqzVDpIn3/tOIH AeYTmEC3miLnI4kw+lr5gZz9PaMAp8r2KQPUgWxVJ9jRKtegT7ssIIl6iYtxK2BJQp qU1frpFqrNgzR51rIh+4bp7WttnvG3UzzMtA526sbEGsGaTHHBLsnmxCUpFgIk8zvZ yIevL6x2J423d9P/iBJrdIXdztXcnTrZG0i/z9jf4N+qqun0SWqiQlmnIShS5QUVA6 t+dRTtAc7JzeUV1RcV7s3r+5A3eAoq9VZERbHlnKxYDd5L4hDxwqC3v7qOvWPNvpGS nRkF1slY/EhpQ== 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.19 028/109] net: rds: fix memory leak in rds_recvmsg Date: Mon, 28 Jun 2021 10:31:44 -0400 Message-Id: <20210628143305.32978-29-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143305.32978-1-sashal@kernel.org> References: <20210628143305.32978-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.19.196-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.196-rc1 X-KernelTest-Deadline: 2021-06-30T14:32+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 3ca278988b52..ccf0bf283002 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c @@ -705,7 +705,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_recvmsg_zcookie(rs, msg); -- 2.30.2