From patchwork Mon May 18 17:35:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 225685 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 E869FC433E0 for ; Mon, 18 May 2020 18:13:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDA2320671 for ; Mon, 18 May 2020 18:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589825632; bh=/yFRTgkjOjuakAcUHMYNBsrRG7i5WsGSgwVe2mmzVsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JshwJ7foA2BrpCsde8joX6IrvpSVwCu0yMqS/6cxMqHyZN9jttezSGIFK83/6NAwE zpbe+LCrL7P636gXthW4ae2hFfGV2VrlMGSDCPaWpuNuoQ/eLpNRHwI8kB4ueUY4Oa UeCfaOpIa7W6G/4zH+DsCSmhdxlqiGMSmolgZN+Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732431AbgERSNu (ORCPT ); Mon, 18 May 2020 14:13:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:44102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732424AbgERSBj (ORCPT ); Mon, 18 May 2020 14:01:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EBA6E207C4; Mon, 18 May 2020 18:01:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589824899; bh=/yFRTgkjOjuakAcUHMYNBsrRG7i5WsGSgwVe2mmzVsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J/lRikDQ7Ysu0ZUxQ5EySsDMS2+uozAYCUhhZaXzwocipfKfGXH3wMITszSF+/GeD ZzDPb1ga5yva4agvIPe7sPabYlOzXJYPwpRBX3R0KdxpfdGv6Jq/J/tdfJoRfXOfVZ 1MHRxakIE5ODW/7OTh+IFovGpVlBV89aOs6afSy0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Minet , Jakub Kicinski Subject: [PATCH 5.6 049/194] umh: fix memory leak on execve failure Date: Mon, 18 May 2020 19:35:39 +0200 Message-Id: <20200518173535.892437661@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173531.455604187@linuxfoundation.org> References: <20200518173531.455604187@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vincent Minet [ Upstream commit db803036ada7d61d096783726f9771b3fc540370 ] If a UMH process created by fork_usermode_blob() fails to execute, a pair of struct file allocated by umh_pipe_setup() will leak. Under normal conditions, the caller (like bpfilter) needs to manage the lifetime of the UMH and its two pipes. But when fork_usermode_blob() fails, the caller doesn't really have a way to know what needs to be done. It seems better to do the cleanup ourselves in this case. Fixes: 449325b52b7a ("umh: introduce fork_usermode_blob() helper") Signed-off-by: Vincent Minet Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- kernel/umh.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/kernel/umh.c +++ b/kernel/umh.c @@ -475,6 +475,12 @@ static void umh_clean_and_save_pid(struc { struct umh_info *umh_info = info->data; + /* cleanup if umh_pipe_setup() was successful but exec failed */ + if (info->pid && info->retval) { + fput(umh_info->pipe_to_umh); + fput(umh_info->pipe_from_umh); + } + argv_free(info->argv); umh_info->pid = info->pid; }