Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13959079pxu; Mon, 4 Jan 2021 09:01:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAuzetukJUNLWO3Jisv7UirxAWXRighdEyueTbAcwlYtrfr0vbdfkjOdL6jN760tnZGMl4 X-Received: by 2002:a17:907:2071:: with SMTP id qp17mr67916399ejb.110.1609779689926; Mon, 04 Jan 2021 09:01:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609779689; cv=none; d=google.com; s=arc-20160816; b=Usv/6dLc71OlO9BMtKlextwIAY9RPvVU4EVRsNRgqkiijp2+H3Gv25H8zv9xG5Aiih GpKhgtgF0bfPjl0i1oe/oXhnh15BF2aTNzYg5Ug1wVPpQ/vLdijuT4EVKLTssejQBRJv xz9Q2Z85MAWkClgZuuIx7Aivnx+qT186oGIJ6ph/8aOuqe3hc1H8bgfx88REky4EzH+j tmw2BXpfz1tVuen6DAefjtyMDXr5fYdbLzRVysqeSqkjvwxS8Q8LUF6ZXNQq/w/peSKv 1q/RJy9YXCd+VX+hkLvOJuC4yWyfXkjqLoJM+s7blf6ZBPaOuB0YGeLP/pSTd788Az8A Acgg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JFUTkX5AWudVR6KMq3R0z7LC2L7e6LOzM4E5xiEF6Po=; b=0LUZHWpZ0mt9/9SxLENVSCVsx1sc3p/AdLPQ/+OukvgkALdrFOVAVQd5ZxRvZQZIgO IqHJWTGv/TdwQwX9om9w14O+OLK/S08uorDRe+Ll5wJA3tUDMjOr4Mn6D6veGCymdQwD sJ1q8oi1zU9Ue8oesOamixuhRTcdPm3rK/HQk0sMSCnF7QjFPxiSat8h4ybjeXTslr8O TokBCx0dA3xeNBJ+rUcXqmcHDXoZODbwXAjlInaTqn4Ucd/FjRA1qlOdXRicYxy+gE+E Tf7AnYbmCAzzkosEGFR0qhBBd0Lhm7qF2Ki95FT0fzG2Q7PAcDSOfDUsNoH/DfcMka8G 788A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eCSYzgZX; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si34659522edp.592.2021.01.04.09.01.06; Mon, 04 Jan 2021 09:01:29 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=eCSYzgZX; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729421AbhADQLJ (ORCPT + 99 others); Mon, 4 Jan 2021 11:11:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:36558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728275AbhADQAQ (ORCPT ); Mon, 4 Jan 2021 11:00:16 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E5DCB22AB0; Mon, 4 Jan 2021 15:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609775995; bh=3U9d0/nS1d9EMpclSP8nCQLyvH2BWG7hJmgCvL9H/LQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCSYzgZX/NC31eluMSm0t3+PggUEZbbDk0owL/bi15kgh0j+85YFIZ11N7VO6xe57 URYwaEU0SykIoxgm6WZtgs2BB1Dghpx1Ioh//DCREs2Yrm1CTxgdqQrTDo6Vkeo568 t58OSbdZYOpe8OsxI8e8NoOCkZqqwQQhJVU9KBQQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Qinglang Miao , Zefan Li , Tejun Heo Subject: [PATCH 5.4 23/47] cgroup: Fix memory leak when parsing multiple source parameters Date: Mon, 4 Jan 2021 16:57:22 +0100 Message-Id: <20210104155706.860082652@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155705.740576914@linuxfoundation.org> References: <20210104155705.740576914@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qinglang Miao commit 2d18e54dd8662442ef5898c6bdadeaf90b3cebbc upstream. A memory leak is found in cgroup1_parse_param() when multiple source parameters overwrite fc->source in the fs_context struct without free. unreferenced object 0xffff888100d930e0 (size 16): comm "mount", pid 520, jiffies 4303326831 (age 152.783s) hex dump (first 16 bytes): 74 65 73 74 6c 65 61 6b 00 00 00 00 00 00 00 00 testleak........ backtrace: [<000000003e5023ec>] kmemdup_nul+0x2d/0xa0 [<00000000377dbdaa>] vfs_parse_fs_string+0xc0/0x150 [<00000000cb2b4882>] generic_parse_monolithic+0x15a/0x1d0 [<000000000f750198>] path_mount+0xee1/0x1820 [<0000000004756de2>] do_mount+0xea/0x100 [<0000000094cafb0a>] __x64_sys_mount+0x14b/0x1f0 Fix this bug by permitting a single source parameter and rejecting with an error all subsequent ones. Fixes: 8d2451f4994f ("cgroup1: switch to option-by-option parsing") Reported-by: Hulk Robot Signed-off-by: Qinglang Miao Reviewed-by: Zefan Li Signed-off-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- kernel/cgroup/cgroup-v1.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -914,6 +914,8 @@ int cgroup1_parse_param(struct fs_contex opt = fs_parse(fc, &cgroup1_fs_parameters, param, &result); if (opt == -ENOPARAM) { if (strcmp(param->key, "source") == 0) { + if (fc->source) + return invalf(fc, "Multiple sources not supported"); fc->source = param->string; param->string = NULL; return 0;