lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <19598d43-de61-c663-25e8-17b6f5d5ef80@I-love.SAKURA.ne.jp>
Date:   Mon, 4 Jul 2022 22:48:32 +0900
From:   Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
To:     Wedson Almeida Filho <wedsonaf@...gle.com>
Cc:     Greg KH <gregkh@...uxfoundation.org>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Len Brown <len.brown@...el.com>, Pavel Machek <pavel@....cz>,
        arnd@...db.de, linux-kernel@...r.kernel.org,
        linux-pm@...r.kernel.org
Subject: Re: [PATCH] char: misc: make misc_open() and misc_register() killable

On 2022/07/04 21:59, Wedson Almeida Filho wrote:
>> @@ -139,6 +139,10 @@ static int misc_open(struct inode *inode, struct file *file)
>>  
>>  	err = 0;
>>  	replace_fops(file, new_fops);
>> +	if (iter->unlocked_open && file->f_op->open) {
>> +		mutex_unlock(&misc_mtx);
>> +		return file->f_op->open(inode, file);
>> +	}
> 
> One of the invariants of miscdev is that once misc_deregister() returns,
> no new calls to f_op->open() are made. (Although, of course, you can
> still have open files but that's a whole different problem.)

The point of this change is that file->f_op after mutex_unlock(&misc_mtx) is
 from new_fops which is guaranteed to hold a ref on "struct file_operations"
via new_fops = fops_get("struct miscdevice"->fops).
That is, a module ref remains valid even after mutex_unlock(&misc_mtx).

And as with major_names_lock case quoted below, this change assumes that
misc_deregister() is called from module's __exit function, and fops_get()
is preventing the module owning new_fops from calling __exit function.

+		if ((*n)->major != major || !(*n)->probe)
+			continue;
+		if (!try_module_get((*n)->owner))
+			break;
+		/*
+		 * Calling probe function with major_names_lock held causes
+		 * circular locking dependency problem. Thus, call it after
+		 * releasing major_names_lock.
+		 */
+		probe_fn = (*n)->probe;
+		mutex_unlock(&major_names_lock);
+		/*
+		 * Assuming that unregister_blkdev() is called from module's
+		 * __exit function, a module refcount taken above allows us
+		 * to safely call probe function without major_names_lock held.
+		 */
+		probe_fn(devt);
+		module_put((*n)->owner);
+		return;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ