From nobody@FreeBSD.org  Mon Jun 27 12:22:47 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B479B106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Jun 2011 12:22:47 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id A515C8FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Jun 2011 12:22:47 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p5RCMlRi093304
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Jun 2011 12:22:47 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p5RCMlx2093301;
	Mon, 27 Jun 2011 12:22:47 GMT
	(envelope-from nobody)
Message-Id: <201106271222.p5RCMlx2093301@red.freebsd.org>
Date: Mon, 27 Jun 2011 12:22:47 GMT
From: Greg Becker <greg@codeconcepts.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: replay_alloc() could dereference a null pointer...
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         158339
>Category:       kern
>Synopsis:       [rpc] [patch] replay_alloc() could dereference a null pointer...
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pjd
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 27 12:30:09 UTC 2011
>Closed-Date:    
>Last-Modified:  Tue Jun 28 12:59:25 UTC 2011
>Originator:     Greg Becker
>Release:        8.2
>Organization:
CodeConcepts
>Environment:
FreeBSD dev4.i.cacheiq.com 8.2-STABLE FreeBSD 8.2-STABLE #5: Wed Jun 22 11:11:13 CDT 2011     gbecker@dev4.i.cacheiq.com:/usr/obj/usr/src/sys/DEV4  amd64


>Description:
relay_alloc() (in src/sys/rpc/replay.c) calls malloc() with the M_NOWAIT
flag, then proceeds to assume the pointer returned by malloc() is not
NULL.  This could cause a panic in a situation in which malloc() cannot
satisfy the request.

>How-To-Repeat:

>Fix:
Check the return code from malloc().  See attached patch.

Patch attached with submission follows:

--- /usr/src/sys/rpc/replay.c	2011-06-27 06:47:01.000000000 -0500
+++ /home/gbecker/replay.c	2011-06-27 06:46:21.000000000 -0500
@@ -115,14 +115,12 @@
 
 	rc->rc_count++;
 	rce = malloc(sizeof(*rce), M_RPC, M_NOWAIT|M_ZERO);
-	if (rce) {
-		rce->rce_hash = h;
-		rce->rce_msg = *msg;
-		bcopy(addr, &rce->rce_addr, addr->sa_len);
+	rce->rce_hash = h;
+	rce->rce_msg = *msg;
+	bcopy(addr, &rce->rce_addr, addr->sa_len);
 
-		TAILQ_INSERT_HEAD(&rc->rc_cache[h], rce, rce_link);
-		TAILQ_INSERT_HEAD(&rc->rc_all, rce, rce_alllink);
-	}
+	TAILQ_INSERT_HEAD(&rc->rc_cache[h], rce, rce_link);
+	TAILQ_INSERT_HEAD(&rc->rc_all, rce, rce_alllink);
 
 	return (rce);
 }


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: glebius 
State-Changed-When: Tue Jun 28 12:58:50 UTC 2011 
State-Changed-Why:  
This had been already fixed in head/ by pjd. 


Responsible-Changed-From-To: freebsd-bugs->pjd 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Tue Jun 28 12:58:50 UTC 2011 
Responsible-Changed-Why:  
This had been already fixed in head/ by pjd. 

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