From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754583AbbIIP4M (ORCPT ); Wed, 9 Sep 2015 11:56:12 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:65100 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752988AbbIIP4K (ORCPT ); Wed, 9 Sep 2015 11:56:10 -0400 From: Arnd Bergmann To: Jon Hunter Cc: Ulf Hansson , grundler@google.com, olofj@chromium.org, Seshagiri Holi , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mmc: block: Add new ioctl to send multi commands Date: Wed, 09 Sep 2015 17:56:05 +0200 Message-ID: <1481090.IIYrKtDeR0@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <1441811161-18513-1-git-send-email-jonathanh@nvidia.com> References: <1441811161-18513-1-git-send-email-jonathanh@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:z6e2zjjRsiuia2GlCY5RhrM1OIGuausJCk+qp11hJvlTh2CDR0k kj/WrkLj8GTCOx6aI9SvMEh1whk3iHwksDIDWVfdWRKFfGcU39nEE7h7CGmsQT6Q3MBc1Ne D75l7CMw50psDJL4QNDTR9y14jB5UiaDTdirrInxD5JZfjqL1ncr3mXVuP/9gYZQ6nPDBNz hsYI0rzJE3CVr6zBdJOLA== X-UI-Out-Filterresults: notjunk:1;V01:K0:yrKsu/AtKrQ=:UEOdCKQ/XqCWld7tFyDdR1 ZnjpRzBd0IYNSkdDcEPALuDGQ41ElP07Mm0LdgT13du9PV+BhE/ZTxu6R+yWvYdCG7+54y9S1 apDhqth5/+PtFrRZlWTgsXm1XvN/BYjIWezYpNWeQoHXQ4uYEa+3c4QXwjGDCLSvgUEpgpqAQ HaUPdg4aLjGCvPPpt3FQ1gc3islHCMFJ+4UXVZh0eoQe0NS8Idq8LzcArjfgCkRVDHWjFdSs+ +rXW4HHoa2dA0ebdMDayCuoeP3rj6EYlwsEvVG4/Vz2roIG39wS55jfhCIcYFbKM+jdx3y0QC +1RTVDD49qrQfu1cJW2wEkzd6Yyf2IyXZVtGvGiQ55XGZBuP5PnF+F7ePeSQcVrYrcwoNwGre 8xg0x29IJPeCvIXnYE9Lk3Rw5XsrDuYF8OjhnV5ml/kKcumnkMVWfTjmIfmU90vvaoQ0nQS9o jjHE+ixKqS38BvYLu5G3U61afFCBb909o5ksee7Z3wXFv8gXpg1e5vdlf1e2OG9s/XUujPq58 k5brwbeH9GrX4TQz1rlRPxWbxUOPAJTUB9YFLdyIzXraqiG4mrKMjPpM/vYzUwMzACfd3gwuQ Iaa/8yhlslqMY1VKnk4wHotH8Auma14sGTsrCPQZ02fh3TGGBIki2UMc4M/2g9Rb1OtOUAI5K u4SpU/5Mc6DXWLER/EGCjEiaAgIBA/MxQS0SxQJNz8au7wig9p47Cq4+do9cvlC1KGXiX8U00 IZzxq7npBjBqrzBP Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday 09 September 2015 16:06:01 Jon Hunter wrote: > + > + idata = kcalloc(mcci.num_of_cmds, sizeof(*idata), GFP_KERNEL); > + if (!idata) { > + err = -ENOMEM; > + goto cmd_err; > + } > + > + cmds = (struct mmc_ioc_cmd __user *)(unsigned long)mcci.cmds_ptr; > + for (n_cmds = 0; n_cmds < mcci.num_of_cmds; n_cmds++) { > + idata[n_cmds] = mmc_blk_ioctl_copy_from_user(&cmds[n_cmds]); > + if (IS_ERR(idata[n_cmds])) { > + err = PTR_ERR(idata[n_cmds]); > + goto cmd_err; > + } > + } > + You have no upper bound on the number of commands, which means you end up catching overly large arguments only through -ENOMEM. Can you come up with an upper bound that is guaranteed to succeed with the allocation? Or would it be possible to process the user data one at a time while going through the commands? > +struct mmc_ioc_multi_cmd { > + __u64 cmds_ptr; > + uint8_t num_of_cmds; > +}; complex commands are always nasty in one way or another. Can you describe in the patch description why you picked an indirect pointer over something like struct mmc_ioc_multi_cmd { __u64 num_of_cmds; struct mmc_ioc_cmd cmds[0]; }; as I said, both are ugly. My first choice would have been the other one, but I'm sure you have some reasons yourself. Arnd