From owner-freebsd-arch@FreeBSD.ORG Sat Dec 2 16:24:37 2006 Return-Path: X-Original-To: arch@freebsd.org Delivered-To: freebsd-arch@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8D07816A416 for ; Sat, 2 Dec 2006 16:24:37 +0000 (UTC) (envelope-from alexander@leidinger.net) Received: from redbull.bpaserver.net (redbullneu.bpaserver.net [213.198.78.217]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7413B43CAF for ; Sat, 2 Dec 2006 16:24:15 +0000 (GMT) (envelope-from alexander@leidinger.net) Received: from outgoing.leidinger.net (p54A5DDF4.dip.t-dialin.net [84.165.221.244]) by redbull.bpaserver.net (Postfix) with ESMTP id D5CA52E04C for ; Sat, 2 Dec 2006 17:24:30 +0100 (CET) Received: from Magellan.Leidinger.net (Magellan.Leidinger.net [192.168.1.1]) by outgoing.leidinger.net (Postfix) with ESMTP id A868B5B4C6C for ; Sat, 2 Dec 2006 17:24:07 +0100 (CET) Date: Sat, 2 Dec 2006 17:25:00 +0100 From: Alexander Leidinger To: arch@freebsd.org Message-ID: <20061202172500.62b03d9c@Magellan.Leidinger.net> X-Mailer: Sylpheed-Claws 2.6.0 (GTK+ 2.10.6; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BPAnet-MailScanner-Information: Please contact the ISP for more information X-BPAnet-MailScanner: Found to be clean X-BPAnet-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-14.864, required 6, autolearn=not spam, BAYES_00 -15.00, DK_POLICY_SIGNSOME 0.00, FORGED_RCVD_HELO 0.14) X-BPAnet-MailScanner-From: alexander@leidinger.net X-Spam-Status: No Cc: Subject: Changing copyinstr(9) invariants X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Dec 2006 16:24:37 -0000 Hi, the copyinstr(9) documentation does not guarantee that in the ENAMETOOLONG case the result is a completely filled up memory region which contains a truncated string without termination. The powerpc version works like this. And while I don't understand i386 ASM, it looks to me the i386 version does the same. My questions: - Does the amd64/sparc64/ia64/... version do the same? - Are there reasons not to document this fact and then make use of it? My motivation is in the linux_prctl() function in src/sys/compat/linux/linux_misc.c: ---snip--- case LINUX_PR_SET_NAME: max_size = MIN(sizeof(comm), sizeof(p->p_comm)); error = copyinstr((void *)(register_t) args->arg2, comm, max_size, NULL); /* Linux silently truncates the name if it is too long. if (error == ENAMETOOLONG) { /* * XXX: copyinstr() isn't documented to populate the * array completely, so do a copyin() to be on the * safe side. This should be changed in case * copyinstr() is changed to guarantee this. */ error = copyin((void *)(register_t)args->arg2, comm, max_size - 1); comm[max_size - 1] = '\0'; } if (error) return (error); ---snip--- By documenting this behavior I could get rid of the copyin() and just terminate the string. Bye, Alexander. -- 'I'll tell you this!' shouted Rincewind. 'I'd rather trust me than history! Oh, shit, did I just say that?' (Interesting Times) http://www.Leidinger.net Alexander @ Leidinger.net: PGP ID = B0063FE7 http://www.FreeBSD.org netchild @ FreeBSD.org : PGP ID = 72077137