From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS 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 33039C43381 for ; Wed, 20 Feb 2019 16:00:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0363821848 for ; Wed, 20 Feb 2019 16:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550678458; bh=F1Q/P7DdfLeKP0Nrg+92DFsHJ1eg75+UzrWNUXlnLHw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=F92rAUo4UPA4WsO3prQxedBD6Ba7OwZngK/n5kzrMy8AL/kwv+cSW4QpS2cIpuy2q JLEeoB9gkf7LinSNGITKJoLwCCJjIpom4IhdUxZHB5xjm5z3gzfCSj61rbgnCDNteZ D8LTL55BuvmX8g8vuan1n34uLGP7LYtX+Qj3qVlI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726363AbfBTQA4 (ORCPT ); Wed, 20 Feb 2019 11:00:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:60874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfBTQAz (ORCPT ); Wed, 20 Feb 2019 11:00:55 -0500 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 E09062147A; Wed, 20 Feb 2019 16:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550678454; bh=F1Q/P7DdfLeKP0Nrg+92DFsHJ1eg75+UzrWNUXlnLHw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bRnWv6vnSU03hzz6lvmR09E6Y/DdNOR4MDD5s3i86IgGVe4HAp6sjkWAwVQlzYsMk zDrTP7V6gSBsb4Decns344yge1MVx57liCO8rCLiZ+61UJtRK/r1v/bXtpzvQReOdz h1qEk274GKLB0/7kLn8G7yY/m9M+bDP0spcHal4c= Date: Thu, 21 Feb 2019 01:00:52 +0900 From: Masami Hiramatsu To: Jann Horn Cc: Ingo Molnar , Steven Rostedt , kernel list , Song Liu Subject: Re: [PATCH] perf/core: use strndup_user() instead of buggy open-coded version Message-Id: <20190221010052.4da503e3c4252d46620c8276@kernel.org> In-Reply-To: References: <20190218220723.176737-1-jannh@google.com> <20190219204502.d0c4f95d1cda533990d96cd9@kernel.org> <20190219235122.b9f8c6c47392a27131526018@kernel.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jann, On Wed, 20 Feb 2019 16:19:10 +0100 Jann Horn wrote: > On Tue, Feb 19, 2019 at 3:51 PM Masami Hiramatsu wrote: > > On Tue, 19 Feb 2019 20:45:02 +0900 > > Masami Hiramatsu wrote: > > > > > On Mon, 18 Feb 2019 23:07:23 +0100 > > > Jann Horn wrote: > > > > > > > The first version of this method was missing the check for > > > > `ret == PATH_MAX`; then such a check was added, but it didn't call kfree() > > > > on error, so there was still a small memory leak in the error case. > > > > Fix it by using strndup_user() instead of open-coding it. > > > > > > > > > > This looks good to me. > > > > > > Reviewed-by: Masami Hiramatsu > > > > BTW, I think it should note that if the string is longer than PATH_MAX. > > caller will receive -EINVAL instead of -E2BIG with this fix. > > Oh, whoops, I hadn't noticed that. > > Do you want me to just add a note to the changelog, or do I have to > work around this in the code? I think work around will be good if this goes to stable, since I guess this return code may go to user space. Thank you, > > > > > Fixes: 0eadcc7a7bc0 ("perf/core: Fix perf_uprobe_init()") > > > > Signed-off-by: Jann Horn > > > > --- > > > > compile-tested only > > > > > > > > kernel/trace/trace_event_perf.c | 14 +++++--------- > > > > 1 file changed, 5 insertions(+), 9 deletions(-) > > > > > > > > diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c > > > > index 76217bbef815..c744b02081c3 100644 > > > > --- a/kernel/trace/trace_event_perf.c > > > > +++ b/kernel/trace/trace_event_perf.c > > > > @@ -299,15 +299,11 @@ int perf_uprobe_init(struct perf_event *p_event, > > > > > > > > if (!p_event->attr.uprobe_path) > > > > return -EINVAL; > > > > - path = kzalloc(PATH_MAX, GFP_KERNEL); > > > > - if (!path) > > > > - return -ENOMEM; > > > > - ret = strncpy_from_user( > > > > - path, u64_to_user_ptr(p_event->attr.uprobe_path), PATH_MAX); > > > > - if (ret == PATH_MAX) > > > > - return -E2BIG; > > > > - if (ret < 0) > > > > - goto out; > > > > + > > > > + path = strndup_user(u64_to_user_ptr(p_event->attr.uprobe_path), > > > > + PATH_MAX); > > > > + if (IS_ERR(path)) > > > > + return PTR_ERR(path); > > > > if (path[0] == '\0') { > > > > ret = -EINVAL; > > > > goto out; -- Masami Hiramatsu