From owner-freebsd-ports@freebsd.org Sun Jan 31 03:23:36 2016 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 909C5A73E55 for ; Sun, 31 Jan 2016 03:23:36 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [IPv6:2001:470:1f05:b76::196]) by mx1.freebsd.org (Postfix) with ESMTP id 82DBBD6D for ; Sun, 31 Jan 2016 03:23:36 +0000 (UTC) (envelope-from alfred@freebsd.org) Received: from Alfreds-MacBook-Pro-2.local (unknown [IPv6:2601:645:8001:cee1:8cb2:4dd5:40a0:be16]) by elvis.mu.org (Postfix) with ESMTPSA id 426A5345A92E; Sat, 30 Jan 2016 19:23:36 -0800 (PST) Subject: Re: thread-unsafety problems as spl*() ones are NOP To: mokhi , freebsd-current References: From: Alfred Perlstein Organization: FreeBSD Message-ID: <56AD7E37.5050604@freebsd.org> Date: Sat, 30 Jan 2016 19:23:35 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Jan 2016 03:23:36 -0000 On 1/30/16 6:56 AM, mokhi wrote: > Hi. > in kbd.c there are many places spltty()/splx() used assuming it locks/unlocks. > though there is bug filed for this, and ive asked in #bsddev, Ive > preferred to ask and ensure it from here again. > As these functions are obsoleted now, this assumption is incorrect and > some places we have thread-unsafely which leads to security problems > (and/or for example double-free, etc) > > can i use mutex/spin/lock/unlock under where assumed a lock/unlock by > using spltty()/splx() to patch it? > > Thanks, Mokhi. > Sort of, you have to also make sure to understand any locks being held when entering the kbd.c as well as knowing how/when to drop locks using msleep() to make it safe. My understanding is that kdb is locked by GIANT which is why have spls as nops is OK (my knowledge may be out of date), still taking out from under Giant would be nice as it would be one less place under Giant. Have a go at it and post patches and let us know how it goes. -Alfred