Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3202849pxu; Tue, 15 Dec 2020 00:54:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyaugSEhi5Y9QGO7LQ7eQlShB9Dvx9jtYysRv6wmJ45ZLw9HvLfCSloukC8fWMMuwBs+Og X-Received: by 2002:a17:907:101c:: with SMTP id ox28mr24432867ejb.201.1608022440826; Tue, 15 Dec 2020 00:54:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608022440; cv=none; d=google.com; s=arc-20160816; b=HUaZbxmQzjVWnAi/MvizstLphqxYi0NQ6yZCiYXmeWYah7W+qhxpFv1n+sONyIXy+j GHbvw7gTLfUOZPbJZ9Xk2pdxVnSLsjJn+zQSTWhZ2fsfMPIGko0GyCaX5fa9NKeUUCFw gAlwSnoIQSQrDnvovplAawimmfAdEko8hGRfcHd/oLkZny6lwMp+OutsuCDgAlHWelZT 628shhh0XbELyIYxPiWimdNkVUxMLsEQCi+UJojZjKiZ18tbNHUrANw2iVeAguuBpsCZ DjMGsh6Qc5r7It7YgIMDAehdCKW1wbdbNowakuWwNMscR2aeyVUPlNg6F6qqGNI9XTEq 9Yhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=3PP506CzJT/kTRgPrSWNtQ2eQxA80nYDJezNFoHkoFs=; b=CxiT0MT52nQPCh7tnDfEoebBJkipW7u0iCH1O3a5Xj6QAIeXF8b0SvYWx6NVU1hW5j lB2SQeT6hiEt//rj1J2n0PLnGF8dCdaftIDmoH8aCv8BBjQLmgwNaNIOJkR34NLQv8Zl BwFsuQNT7qqAncNVjRlYt7YF6HLvqM4be8cJcv2WS2DlKUMnrAPWNeENAo6C+mQRt/0b mNvaaLrGZnpWL5Phvrjt6KzLpb1Lc9ALK6PLlFkDb0q/AfeVr0Pt1FUDR3TK/1FRvBTA mkuLCKv0W37Js7MuozOtQDA/rNxnBxCFg6v66WmJIm3QGIw2H2nTmluI+kRr6/Z6r0vj mFqQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lz11si560724ejb.341.2020.12.15.00.53.37; Tue, 15 Dec 2020 00:54:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727476AbgLOIvA (ORCPT + 99 others); Tue, 15 Dec 2020 03:51:00 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9530 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727452AbgLOIvA (ORCPT ); Tue, 15 Dec 2020 03:51:00 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CwBlS1TywzhshF; Tue, 15 Dec 2020 16:49:40 +0800 (CST) Received: from [10.174.179.9] (10.174.179.9) by smtp.huawei.com (10.3.19.202) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 15 Dec 2020 16:50:07 +0800 Subject: Re: [PATCH v2] cgroup: Fix memory leak when parsing multiple source parameters To: Qinglang Miao , Tejun Heo , Johannes Weiner CC: , References: <20201209121322.77665-1-miaoqinglang@huawei.com> <20201210012943.92845-1-miaoqinglang@huawei.com> From: Zefan Li Message-ID: Date: Tue, 15 Dec 2020 16:50:07 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20201210012943.92845-1-miaoqinglang@huawei.com> Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.9] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (didn't notice you've sent v2 with the printk msg fixed) On 2020/12/10 9:29, Qinglang Miao wrote: > 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 > --- > v1->v2: fix compile problems caused by superfluous LF in err message. > kernel/cgroup/cgroup-v1.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c > index 191c329e4..32596fdbc 100644 > --- a/kernel/cgroup/cgroup-v1.c > +++ b/kernel/cgroup/cgroup-v1.c > @@ -908,6 +908,8 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param) > 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"); Reviewed-by: Zefan Li