From patchwork Tue Jun 8 08:06:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Skripkin X-Patchwork-Id: 12305695 X-Patchwork-Delegate: jgg@ziepe.ca 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 10676C47082 for ; Tue, 8 Jun 2021 08:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EAEE261249 for ; Tue, 8 Jun 2021 08:08:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbhFHIKF (ORCPT ); Tue, 8 Jun 2021 04:10:05 -0400 Received: from mail-lf1-f41.google.com ([209.85.167.41]:40469 "EHLO mail-lf1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbhFHIKF (ORCPT ); Tue, 8 Jun 2021 04:10:05 -0400 Received: by mail-lf1-f41.google.com with SMTP id w33so30732259lfu.7; Tue, 08 Jun 2021 01:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lnqh2KFBanSAc5Sbde66Uudde2Nu0b01lQi+nfaMyCU=; b=DqsatKiRTA/YuW1kJivNqJcOmvLcRweI14FJc9DaMPE/P2aovac65RbISuumMiu5a8 pjFMf/BR4PlGm0tF4lLduN2WPzXcOSyh6TEzBwI7rnia+X9Cw2MNOS5OKtA+FOzhFfDE 9D++TqnrsSWsQdteYwLcmQxWL6qb7ePxgc5hIUtPO3jj3cIjLP0fzFYZDn6uUxeYtpsS A8/7af2U8HhngQ2TB+Ra9mtc4Gkom6BgSbGWavnM2VQqHzGu70KFd6aHGkeWDFLMe6KK fRmEEcSmvAg1IH+6sgXpoB/cAd8IDTMHf5796y4X5jcj1H9CRV7+IybGnmPcEXvJqYUC wcEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lnqh2KFBanSAc5Sbde66Uudde2Nu0b01lQi+nfaMyCU=; b=PAM2WkUsYO+69ETuQqeIxcfwzOOEpeYlWF542mJG4wagWenPD0fT8ZYUkQIH2w0Olp UvRU0+KNwOSFNpBUb/oYRcnnYTd1mW1A2B1QQH3C2QJi3qYhh8OMPSBjB5Kpl44kqRcw FjsmaJjLmWgG/TIfpILAYdXGesKE3XISuj5D1PAXix0QssBrfWhHaYnMzwlKy1LyqATP nDfiBlaoMM7K4fz0wYkVsnrvoadLw8vUuluJ7JvA+kqxSQs4BxPB7CfUIWf13a/0QrmK qeaYXhFufOoY+zJSsdZ8jVxAXkpYVua89jMzTwtUK8FAJvZS8CyRAuV1VeyZuPbBvlzG J7Qg== X-Gm-Message-State: AOAM532XsDqbqNz+VWRQ5i9jfhvMisEcPSRB1jTWKis6M1iFcr4t0zJj WKAnDb3OFcA1gf3fTa64CzA= X-Google-Smtp-Source: ABdhPJzPIltCu2GVDqjHbfuKru8AgxKbx64lQuNgfgDY/ZF4T9YYZPAo6iVbKfqhTp6FzkKNUNZIxA== X-Received: by 2002:a19:f509:: with SMTP id j9mr14691310lfb.80.1623139631179; Tue, 08 Jun 2021 01:07:11 -0700 (PDT) Received: from localhost.localdomain ([94.103.224.40]) by smtp.gmail.com with ESMTPSA id k21sm521789lfu.38.2021.06.08.01.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 01:07:10 -0700 (PDT) From: Pavel Skripkin To: santosh.shilimkar@oracle.com, davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org, Pavel Skripkin , syzbot+5134cdf021c4ed5aaa5f@syzkaller.appspotmail.com Subject: [PATCH v2] net: rds: fix memory leak in rds_recvmsg Date: Tue, 8 Jun 2021 11:06:41 +0300 Message-Id: <20210608080641.16543-1-paskripkin@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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 --- Changes in v2: Changed goto to break. --- 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 4db109fb6ec2..5b426dc3634d 100644 --- a/net/rds/recv.c +++ b/net/rds/recv.c @@ -714,7 +714,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);