Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751547AbbLKARg (ORCPT ); Thu, 10 Dec 2015 19:17:36 -0500 Received: from lxorguk.ukuu.org.uk ([81.2.110.251]:49160 "EHLO lxorguk.ukuu.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750826AbbLKARe (ORCPT ); Thu, 10 Dec 2015 19:17:34 -0500 Date: Fri, 11 Dec 2015 00:17:20 +0000 From: One Thousand Gnomes To: Wim de With Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] staging: gdm72xx: add userspace data struct Message-ID: <20151211001720.2332a513@lxorguk.ukuu.org.uk> In-Reply-To: <20151210234738.GA28422@boole.wimdewith.com> References: <20151210113421.GE5284@mwanda> <1449747648-24347-1-git-send-email-nauxuron@wimdewith.com> <20151210144445.669ea27a@lxorguk.ukuu.org.uk> <20151210234738.GA28422@boole.wimdewith.com> Organization: Intel Corporation X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; 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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 11 Dec 2015 00:47:38 +0100 Wim de With wrote: > On Thu, Dec 10, 2015 at 02:44:45PM +0000, One Thousand Gnomes wrote: > > (except that you mean sizeof(struct fsm_s) and it doesn't compile at the > > moment! > > Oops, sloppy mistake. Compile/test/send - even when in a hurry > > data_s can just be modified to be __user. All uses of it follow that > > rule. > > What do you mean? The data still needs to be copied from user space to kernel > space, if I'm not mistaken. And not all uses follow that rule, since in both > gdm_wimax_ioctl_get_data() and gdm_wimax_ioctl_set_data() it is used as both > the source and destination in the copy_from_user() and copy_to_user() call. Good point I missed that. > > All I think you need in this case is > > > > struct fsm_s fsm_buf; > > > > if (copy_from_user(&fsm_buf, req->data.buf,sizeof(buf)) > > return -EFAULT > > gdm_update_fsm(&fsm_buf); > > Do you mean sizeof(fsm_s)? I realize this would have been far simpler than my > overkill solution. Yes either sizeof(struct fsm_s) or sizeof(fsm_buf). The former is often safer. > > If you are touching the structs it might be wise to fix the other > > problems with them notably the use of int. sizes when used are unsigned - > > and signed sizes are asking for errors. In fact if you look at the > > existing uses of the size checks they look deeply suspicious the moment > > anything malicious passes in negative numbers. > > I would love to do that, but it is a bit outside the scope of this patch, so I > would rather safe this for another patch. Absolutely right - it should be another patch Alan