From owner-freebsd-bugs@FreeBSD.ORG Wed Feb 25 21:40:04 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2EA58106567C for ; Wed, 25 Feb 2009 21:40:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 1D5DB8FC13 for ; Wed, 25 Feb 2009 21:40:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n1PLe3x1096564 for ; Wed, 25 Feb 2009 21:40:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n1PLe38Z096563; Wed, 25 Feb 2009 21:40:03 GMT (envelope-from gnats) Date: Wed, 25 Feb 2009 21:40:03 GMT Message-Id: <200902252140.n1PLe38Z096563@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Dylan Cochran Cc: Subject: Re: kern/132104: kenv buffer overflow X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Dylan Cochran List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Feb 2009 21:40:04 -0000 The following reply was made to PR kern/132104; it has been noted by GNATS. From: Dylan Cochran To: Jaakko Heinonen Cc: bug-followup@freebsd.org Subject: Re: kern/132104: kenv buffer overflow Date: Wed, 25 Feb 2009 16:36:32 -0500 On Wed, Feb 25, 2009 at 1:56 PM, Jaakko Heinonen wrote: > > Hi, > > On 2009-02-25, Dylan Cochran wrote: >> This prevents the panic condition, but also increases the amount of >> time the mutex is held. Comments? >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 mtx_lock(&kenv_lock); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 cp =3D _getenv_dynamic(name, NULL); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (cp !=3D NULL) { >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 strcpy(buf, cp); >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mtx_unlock(&kenv_lock); >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =3D strlen(buf) + 1; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 len =3D strlen(cp) + 1; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D malloc(len, M_KENV, = M_WAITOK); >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 strcpy(ret, buf); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 strcpy(ret, cp); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mtx_unlock(&kenv_lock); > > malloc(9) with M_WAITOK flag could sleep. You are not allowed to sleep > while holding a mutex. So if I modify it to use M_NOWAIT, I should unlock if it returns null, then sleep, then relock, and repeat? I'd rather not just bump up the *LEN values, or truncate it by adding a trailing 0 byte to the end. Not in 2009 anyway. > > -- > Jaakko >