Re: Open Sound System - OSS "soundon" command causes KERNEL PANIC FreeBSD-11

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Thu, 11 Feb 2016 12:14:18 +0200
On Thu, Feb 11, 2016 at 07:54:57AM +0100, Hans Petter Selasky wrote:
> On 02/11/16 03:02, Greg Quinlan wrote:
> > Hi HPS,
> > Note: Does not happen on FreeBSD 10.1-Stable!
> >
> 
> Yes, that's because WITNESS is off in 10.x by default.
> 
> Does the attached patch solve your problem?
No, the patch below does not solve the issue, it only papers over it.
I object against committing this change.

Issue is that, if called unlocked, the result from module_lookupbyname()
could become invalid right after receiving.  It is the duty of the caller
of the function to ensure that the result is still valid, and the only
way to achieve it is to own the lock around the whole code region which
calls the function and utilizes its result.

A bug is in the OSS code.
> 
> --HPS
> 

> Index: sys/kern/kern_module.c
> ===================================================================
> --- sys/kern/kern_module.c	(revision 295464)
> +++ sys/kern/kern_module.c	(working copy)
> _at__at_ -214,16 +214,24 _at__at_
>  module_lookupbyname(const char *name)
>  {
>  	module_t mod;
> +	int xlocked;
>  	int err;
>  
> -	MOD_LOCK_ASSERT;
> -
> +	/*
> +	 * If the context is not properly locked, apply the proper
> +	 * locks here:
> +	 */
> +	xlocked = sx_xlocked(&modules_sx);
> +	if (!xlocked)
> +		MOD_SLOCK;
>  	TAILQ_FOREACH(mod, &modules, link) {
>  		err = strcmp(mod->name, name);
>  		if (err == 0)
> -			return (mod);
> +			break;
>  	}
> -	return (NULL);
> +	if (!xlocked)
> +		MOD_SUNLOCK;
> +	return (mod);
>  }
>  
>  module_t

> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
Received on Thu Feb 11 2016 - 09:14:25 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:02 UTC