Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp916053pxk; Sat, 12 Sep 2020 04:50:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvJSDa5I6GKXUMmmwC9FCWNmfoRhVFUkXgdma8AlTaqq7W3EHlNaqYqcgAD/+3b11BsNvX X-Received: by 2002:a17:906:3e90:: with SMTP id a16mr5423423ejj.363.1599911417312; Sat, 12 Sep 2020 04:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599911417; cv=none; d=google.com; s=arc-20160816; b=BALdupVLFUxgyeBtvuhpoo/W4cFK38M+064T43VfhWLZGlgsdP9KIgbq4TfnauXQyP KvdnVfvxVMdebFQiqLafcUqw8hcqS6Y/sxIYzumQDamwAupEEb06BsZYAfHsE/UtORjB 4zMSB24cL2/ZUd/mYwcZEX7eGTsgN8RxopXEUaTCERAtlN5zefZGyUzM9OKo4HDYdDx/ qzzdoSWahUnHpUwPbdrKdV5hz+OBlajZECPvXdawpfbLbPDMO/6RR8ju4OR5MiQN7eAv jq/JMXnLZHfZnZzjhSexj0LngHPMEBn2yK8BkGuuNIe/IAwUM51K5BPrZlPJW10Ma4bk VN1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=UmBurHSSvntDJMMzS4uMH1rXfE1k+f7rEWmwLSNg4OM=; b=CRYyxPgwxiT+IJ1i1t8DzVVNrzfiNnTM2ykUMPMHbHudRrgyn/yqpWg4v8Bd8pFHK3 uMFXUTnv9wEuH+06ff86ZFfYBSbxSdjGpOjAoeWfoAia3KhaAdz9D5LIung1/l2QxxwQ 2JoA3kNKd9Rb3CyyZBd6pA7ZkkH0GyZf2WYJhPOT+C7ZCybDDir+gPYVjzmFPK8D6ZyW ufql3/NvOn9zdaGhFRCdUInpQ5IInBeZvs6GDxsJZDN2NsRM2YVojKHydmK6CvgK6MGg SdV6nKZLKuSvQBPehfmlxwC2y2Gji9uDCP66UyoY1LvklhaUq15r0hHY5gTWrvPHh9Hr bG+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ir6W8kWK; 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=fail (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 r11si3018897eju.461.2020.09.12.04.49.53; Sat, 12 Sep 2020 04:50:17 -0700 (PDT) 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=@kernel.org header.s=default header.b=Ir6W8kWK; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725846AbgILLs0 (ORCPT + 99 others); Sat, 12 Sep 2020 07:48:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:50812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725852AbgILLrT (ORCPT ); Sat, 12 Sep 2020 07:47:19 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 027F7214D8; Sat, 12 Sep 2020 11:47:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599911223; bh=tcy2pv8jwy7gfP4u9YzIxvq8wYbaPrazMLwunNOxOtM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ir6W8kWKHKmWml+SmsxBudZOi7onIp501EbyEtnnXDc54J75qcJaKzYZsHfimml2k CB7SRGWB7Jdj4ocEg12OCYfbFAugkcOvOh9BBD/126Zu5Xgd+Lzbnj4zgqj/QSPpAx uBGo7/iOuzOLu72E9Jv3ye3bfdLHmzoa9P8dZPKk= Date: Sat, 12 Sep 2020 13:47:06 +0200 From: Greg KH To: Anant Thazhemadam Cc: andriin@fb.com, ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, davem@davemloft.net, hawk@kernel.org, john.fastabend@gmail.com, kafai@fb.com, kpsingh@chromium.org, kuba@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Using a pointer and kzalloc in place of a struct directly Message-ID: <20200912114706.GA171774@kroah.com> References: <000000000000c82fe505aef233c6@google.com> <20200912113804.6465-1-anant.thazhemadam@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200912113804.6465-1-anant.thazhemadam@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 12, 2020 at 05:08:04PM +0530, Anant Thazhemadam wrote: > Updated the usage of a struct variable directly, in bpf_link_get_info_by_fd > to using a pointer of the same type instead, which points to a memory > location allocated using kzalloc. > > Signed-off-by: Anant Thazhemadam Note, your "To:" line seemed corrupted, and why not cc: the bpf mailing list as well? Anyway, comment on your patch below: > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > index 4108ef3b828b..01b9c203ef65 100644 > --- a/kernel/bpf/syscall.c > +++ b/kernel/bpf/syscall.c > @@ -3605,30 +3605,31 @@ static int bpf_link_get_info_by_fd(struct file *file, > union bpf_attr __user *uattr) > { > struct bpf_link_info __user *uinfo = u64_to_user_ptr(attr->info.info); > - struct bpf_link_info info; > + struct bpf_link_info *info = NULL; > u32 info_len = attr->info.info_len; > int err; > > - err = bpf_check_uarg_tail_zero(uinfo, sizeof(info), info_len); > + err = bpf_check_uarg_tail_zero(uinfo, sizeof(struct bpf_link_info), info_len); > + > if (err) > return err; > info_len = min_t(u32, sizeof(info), info_len); > > - memset(&info, 0, sizeof(info)); > - if (copy_from_user(&info, uinfo, info_len)) > + info = kzalloc(sizeof(struct bpf_link_info), GFP_KERNEL); > + if (copy_from_user(info, uinfo, info_len)) > return -EFAULT; You leaked memory :( Did you test this patch? Where do you free this memory, I don't see that happening anywhere in this patch, did I miss it? And odds are this change will slow things down, right? Why make this change, what's wrong with the structure being on the stack? thanks, greg k-h