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=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT 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 DDBEEC282C7 for ; Sat, 26 Jan 2019 17:29:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B34E421872 for ; Sat, 26 Jan 2019 17:29:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbfAZR3d (ORCPT ); Sat, 26 Jan 2019 12:29:33 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:41504 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726089AbfAZR3d (ORCPT ); Sat, 26 Jan 2019 12:29:33 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1gnRlm-0000Ig-UX; Sat, 26 Jan 2019 17:29:27 +0000 Date: Sat, 26 Jan 2019 17:29:26 +0000 From: Al Viro To: Johannes Berg Cc: netdev@vger.kernel.org, Robert O'Callahan , Johannes Berg Subject: Re: [PATCH net 2/4] Revert "kill dev_ifsioc()" Message-ID: <20190126172926.GG2217@ZenIV.linux.org.uk> References: <20190125214320.17685-1-johannes@sipsolutions.net> <20190125214320.17685-3-johannes@sipsolutions.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190125214320.17685-3-johannes@sipsolutions.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, Jan 25, 2019 at 10:43:18PM +0100, Johannes Berg wrote: > From: Johannes Berg > > This reverts commit bf4405737f9f ("kill dev_ifsioc()"). > > This wasn't really unused as implied by the original commit, > it still handles the copy to/from user differently, and the > commit thus caused issues such as > https://bugzilla.kernel.org/show_bug.cgi?id=199469 > and > https://bugzilla.kernel.org/show_bug.cgi?id=202273 > > However, deviating from a strict revert, rename dev_ifsioc() > to compat_ifreq_ioctl() to be clearer as to its purpose and > add a comment. I disagree with solution. Look at what's happening here: > + uifr = compat_alloc_user_space(sizeof(*uifr)); > + if (copy_in_user(uifr, uifr32, sizeof(*uifr32))) > + return -EFAULT; an enlarged copy is made. > + err = sock_do_ioctl(net, sock, cmd, (unsigned long)uifr); ... which hits this: if (copy_from_user(&ifr, argp, ifreq_size)) return -EFAULT; err = dev_ioctl(net, cmd, &ifr, &need_copyout); if (!err && need_copyout) if (copy_to_user(argp, &ifr, ifreq_size)) return -EFAULT; copying that copy into the kernel space, passing _that_ to dev_ioctl(), then, if dev_ioctl() says that this one needs a copyout, we take the modified kernel copy and copy it to (enlarged) userland one. Then > + > + if (!err) { > + switch (cmd) { > + case SIOCGIFFLAGS: > + case SIOCGIFMETRIC: > + case SIOCGIFMTU: > + case SIOCGIFMEM: > + case SIOCGIFHWADDR: > + case SIOCGIFINDEX: > + case SIOCGIFADDR: > + case SIOCGIFBRDADDR: > + case SIOCGIFDSTADDR: > + case SIOCGIFNETMASK: > + case SIOCGIFPFLAGS: > + case SIOCGIFTXQLEN: > + case SIOCGMIIPHY: > + case SIOCGMIIREG: > + if (copy_in_user(uifr32, uifr, sizeof(*uifr32))) > + err = -EFAULT; We duplicate the "needs copyout" logics here, and copy from the enlarged userland instance to the original. It's much too convoluted, and I really wonder if ifreq_size argument is a good idea - AFAICS, it's only introduced to be able to (ab)use sock_do_ioctl() here.