From stefan@fafoe.dyndns.org  Sat Oct 18 09:17:44 2003
Return-Path: <stefan@fafoe.dyndns.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E611216A4B3
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Oct 2003 09:17:44 -0700 (PDT)
Received: from fafoe.narf.at (chello212186121237.14.vie.surfer.at [212.186.121.237])
	by mx1.FreeBSD.org (Postfix) with ESMTP id DC36843F85
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Oct 2003 09:17:43 -0700 (PDT)
	(envelope-from stefan@fafoe.dyndns.org)
Received: from frog.fafoe.narf.at (frog.fafoe.narf.at [192.168.2.101])
	by fafoe.narf.at (Postfix) with ESMTP
	id 4DD6340ED; Sat, 18 Oct 2003 18:17:40 +0200 (CEST)
Received: by frog.fafoe.narf.at (Postfix, from userid 1001)
	id 9D78C1FC; Sat, 18 Oct 2003 18:17:39 +0200 (CEST)
Message-Id: <20031018161739.9D78C1FC@frog.fafoe.narf.at>
Date: Sat, 18 Oct 2003 18:17:39 +0200 (CEST)
From: Stefan Farfeleder <stefan@fafoe.narf.at>
Reply-To: Stefan Farfeleder <stefan@fafoe.narf.at>
To: FreeBSD-gnats-submit@freebsd.org
Cc: stefan@fafoe.narf.at
Subject: [patch] Align smallbits properly in poll()
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         58214
>Category:       kern
>Synopsis:       [patch] Align smallbits properly in poll()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    andre
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 18 09:20:17 PDT 2003
>Closed-Date:    Mon Sep 13 19:48:05 GMT 2004
>Last-Modified:  Mon Sep 13 19:48:05 GMT 2004
>Originator:     Stefan Farfeleder
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
>Environment:
System: FreeBSD frog.fafoe.narf.at 5.1-CURRENT FreeBSD 5.1-CURRENT #1: Sat Oct 18 17:37:40 CEST 2003 freebsd@frog.fafoe.narf.at:/freebsd/testing/obj/freebsd/testing/src/sys/TESTING i386

>Description:
Poll() uses the array smallbits that is big enough to hold 32 struct pollfd's
to avoid calling malloc() on small numbers of fds.  Because smalltype's members
have type char, its address might be misaligned for a struct pollfd.

>How-To-Repeat:
>Fix:
Additionally, bits' type is changed to void * to avoid a cast and allows to get
rid of another one.

--- poll.diff begins here ---
Index: src/sys/kern/sys_generic.c
===================================================================
RCS file: /usr/home/ncvs/src/sys/kern/sys_generic.c,v
retrieving revision 1.125
diff -u -p -r1.125 sys_generic.c
--- src/sys/kern/sys_generic.c	27 Sep 2003 12:53:33 -0000	1.125
+++ src/sys/kern/sys_generic.c	18 Oct 2003 15:10:19 -0000
@@ -938,8 +938,8 @@ poll(td, uap)
 	struct thread *td;
 	struct poll_args *uap;
 {
-	caddr_t bits;
-	char smallbits[32 * sizeof(struct pollfd)];
+	void *bits;
+	struct pollfd smallbits[32];
 	struct timeval atv, rtv, ttv;
 	int error = 0, timo;
 	u_int ncoll, nfds;
@@ -991,7 +991,7 @@ retry:
 	mtx_unlock_spin(&sched_lock);
 	mtx_unlock(&sellock);
 
-	error = pollscan(td, (struct pollfd *)bits, nfds);
+	error = pollscan(td, bits, nfds);
 	mtx_lock(&sellock);
 	if (error || td->td_retval[0])
 		goto done;
--- poll.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->andre 
Responsible-Changed-By: andre 
Responsible-Changed-When: Sat Dec 27 09:14:30 PST 2003 
Responsible-Changed-Why:  
Take over. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=58214 
State-Changed-From-To: open->analyzed 
State-Changed-By: andre 
State-Changed-When: Sun Dec 28 15:46:46 PST 2003 
State-Changed-Why:  
BDE sent me an more detailed explanation of what to do.  I'll 
have a more correct patch soon. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=58214 

From: Stefan Farfeleder <stefan@fafoe.narf.at>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: kern/58214: [patch] Align smallbits properly in poll()
Date: Tue, 17 Aug 2004 15:20:25 +0200

 On Sun, Dec 28, 2003 at 03:48:02PM -0800, Andre Oppermann wrote:
 > BDE sent me an more detailed explanation of what to do.  I'll
 > have a more correct patch soon.
 
 Any news on this PR?
 
 Thanks,
 Stefan
State-Changed-From-To: analyzed->patched 
State-Changed-By: andre 
State-Changed-When: Fri Aug 27 21:24:13 GMT 2004 
State-Changed-Why:  
The fix with a small change from BDE has been committed and is in rev. 1.133 of 
kern/sys_generic.c. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=58214 
State-Changed-From-To: patched->closed 
State-Changed-By: andre 
State-Changed-When: Mon Sep 13 19:47:17 GMT 2004 
State-Changed-Why:  
MFC'd the fix to RELENG_4.  Case closed.  Thanks to all who helped. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=58214 
>Unformatted:
