From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 29 21:23:40 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 644ED1065676 for ; Thu, 29 Apr 2010 21:23:40 +0000 (UTC) (envelope-from czerner.lukas@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.159]) by mx1.freebsd.org (Postfix) with ESMTP id DAD428FC0C for ; Thu, 29 Apr 2010 21:23:39 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id l26so2080763fgb.13 for ; Thu, 29 Apr 2010 14:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:x-x-sender:to:cc :subject:in-reply-to:message-id:references:user-agent:mime-version :content-type; bh=Kv21QVPdcYXfoYBXqUa4/A9XIfXebd6uIcwJ52FzDhs=; b=RfA2dhwdzje5UiVX8UcFghZMYdNl7iFwUacj0cc56d/ZSoynOY9xIHHSLWrT+XhR1H JlBTsz/i1kbmNzEINzOCSQPZztuyfR5GIUvuZ/T7uMS+HIO1yA4795fx1RNXERrmizEi rsiUYINtvDbMgP0iYGZPNaiEbR2QJvmrbQByk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:x-x-sender:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; b=svQ9cJKig4XjFugg1pawXzjts7i8I3DqjGmbk3izJwKhDwO8lN1iGb+3Dr/cUDqK5Q OuUiHNM9fWBc/Uo9KLpkaDPQMrTMWzpP9+5hJ43Y+jmFbdoqTJU2Ed74d8eXcjphNmdb +0fnfnOPN3ePWYv8JBkEf3uaUek99kY1cDf5c= Received: by 10.87.15.35 with SMTP id s35mr2576769fgi.12.1272576206350; Thu, 29 Apr 2010 14:23:26 -0700 (PDT) Received: from a04-0215a.kn.vutbr.cz (a04-0215a.kn.vutbr.cz [147.229.216.20]) by mx.google.com with ESMTPS id e20sm9746303fga.11.2010.04.29.14.23.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 29 Apr 2010 14:23:25 -0700 (PDT) Date: Thu, 29 Apr 2010 23:23:28 +0200 (CEST) From: "=?ISO-8859-15?Q?Luk=E1=A8_Czerner?=" X-X-Sender: bratt@a04-0215a.kn.vutbr.cz To: Ryan Stone In-Reply-To: Message-ID: References: <201004291418.09768.jhb@freebsd.org> <201004291606.35899.jhb@freebsd.org> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1321214282-1272576209=:30007" Cc: freebsd-hackers@freebsd.org, =?ISO-8859-15?Q?Luk=E1=A8_Czerner?= Subject: Re: ioctl, copy string from user X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Apr 2010 21:23:40 -0000 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1321214282-1272576209=:30007 Content-Type: TEXT/PLAIN; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT On Thu, 29 Apr 2010, Ryan Stone wrote: > Date: Thu, 29 Apr 2010 17:19:41 -0400 > From: Ryan Stone > To: LukᨠCzerner > Cc: freebsd-hackers@freebsd.org > Subject: Re: ioctl, copy string from user > > > Apparently I need to tell ioctl how big is the variable I am > > providing to it ([MAXLEN]). The odd thing is, when I have a structure > > like this: > > > > struct lrfs_attach_info { > >        char *name; > >        int priority; > > }; > > > > and I pass the pointer to that structure to the ioctl, it just > > works. I can even use the 'name' string from the structure without > > any problems, apparently it translates the pointer properly, but I > > did not expect this... > > I think that you'll find that what actually happens is that you're > reading from the userspace pointer. That will work as long as the > pointer is mapped, but you'll panic if what it points to gets swapped > out or is invalid. > Hmmm, I can prevent the pointer to be invalidated, but I doubt I can prevent to the pointer to been swapped out. Is there some better way ? Allocate it statically (char name[MAXLEN]), then it gets copied as whole to the kernel space, isn't it ? --8323329-1321214282-1272576209=:30007--