From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 001D942DAE for ; Mon, 3 Jul 2023 11:28:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EF41341151; Mon, 3 Jul 2023 11:28:39 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 222FA40156; Mon, 3 Jul 2023 11:28:37 +0200 (CEST) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QvgWP4ZszzMqHT; Mon, 3 Jul 2023 17:25:21 +0800 (CST) Received: from [10.67.100.224] (10.67.100.224) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 3 Jul 2023 17:28:34 +0800 Subject: Re: [PATCH] eal: fix file descriptor leakage with unhandled messages To: Viacheslav Ovsiienko , CC: , References: <20230628121938.13452-1-viacheslavo@nvidia.com> From: fengchengwen Message-ID: Date: Mon, 3 Jul 2023 17:28:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20230628121938.13452-1-viacheslavo@nvidia.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.100.224] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Acked-by: Chengwen Feng On 2023/6/28 20:19, Viacheslav Ovsiienko wrote: > The sendmsg()/recvmsg() API is used to establish communication between > the DPDK processes. The API supposes inter-process file descriptors > sending and conversion, the recipient sees the resulting descriptors > in the received message - the operating systems creates ones in the > right context. > > The message receiving is performed by EAL in the dedicated thread > and it might happen the message is received by EAL and not handled > by addressed PMD or application due to some reasons (timeouts, race > condition, etc). EAL just dropped unhandled messages causing the > file descriptor leakage if these ones were presented in the message. > > The patch closes the descriptors (if any) in unhandled messages. > > Fixes: 783b6e54971 ("eal: add synchronous multi-process communication") > Cc: stable@dpdk.org > > Signed-off-by: Viacheslav Ovsiienko > --- > lib/eal/common/eal_common_proc.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c > index 1fc1d6c53b..9676dd73c5 100644 > --- a/lib/eal/common/eal_common_proc.c > +++ b/lib/eal/common/eal_common_proc.c > @@ -321,6 +321,15 @@ read_msg(int fd, struct mp_msg_internal *m, struct sockaddr_un *s) > return msglen; > } > > +static void > +cleanup_msg_fds(const struct rte_mp_msg *msg) > +{ > + int i; > + > + for (i = 0; i < msg->num_fds; i++) > + close(msg->fds[i]); > +} > + > static void > process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) > { > @@ -349,8 +358,10 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) > else if (pending_req->type == REQUEST_TYPE_ASYNC) > req = async_reply_handle_thread_unsafe( > pending_req); > - } else > + } else { > RTE_LOG(ERR, EAL, "Drop mp reply: %s\n", msg->name); > + cleanup_msg_fds(msg); > + } > pthread_mutex_unlock(&pending_requests.lock); > > if (req != NULL) > @@ -380,6 +391,7 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) > RTE_LOG(ERR, EAL, "Cannot find action: %s\n", > msg->name); > } > + cleanup_msg_fds(msg); > } else if (action(msg, s->sun_path) < 0) { > RTE_LOG(ERR, EAL, "Fail to handle message: %s\n", msg->name); > } >