From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5DA125F98B for ; Fri, 15 May 2026 12:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778849514; cv=none; b=QMvGw/sVYkgldkdKFvzE019nb8LaQwOpC2WL4kp/4Cz3SVIMC1TYA3IyQlEUM3VYoXx/HMu/b7IPm5q/yTWYJwdOoAex3hrhegwkpWnj8Crs1iHUXUQp6MK4d06Lunq1kFkHya0llQn0O54Se3Bseh4iOkdAtZYu4s0md6KtItc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778849514; c=relaxed/simple; bh=5f70Nv29Q13VO5AQA3OiKEnWGtvPQO5rb0EoY7ttf/8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=pt3jxfAk67Bp1MbGsyU/s1QBx3aTZPqwqi8cy7krVgHmn6xw9CslUbVCNpaN6fy4oSUHXhVklXigOuqsVPjQu8wrCoOYUqebKKEAKmYEZVH5AAjl+MK5sKYtrlLMLu/AF6EWOJUV6GVTkHIyY8JXrJe9FMb3oDdyhF8RBuwApf4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mdiFUFlU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Qk31qP97; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mdiFUFlU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Qk31qP97" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778849503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zfbmQ0gwoj69eyplasZv+fSVpBObd10VoEehjye/I2A=; b=mdiFUFlUo6PyxrbwKdxtGZ8f0oDmU10StaB2M4iBiVbNoITGxZ6paOE6jS/CeEpmtdy1LI ZIgpgw3C0rW75G+U6tayPjMDB4uwR402/EbSDitUg/8H9E+C2enTgVZsoimy95tS8bdPSM ExTKKuGBu/dPjKXNM/itXGUe+QDeSaP29SNtHWFviVSWppp2mUtJzzMJPZlT4q4L0/8P+M EiozC0qR4/AviuzogGXiCkQYCLykvr4+u+a/I/baASaF58T/kJDrGNwkiJePsSNWpMazmF FW33JrvmTNPpXs3uptty0WrKJb09j757VDqzDQSOFbP8WUdlpGW2n9LfssHmxw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778849503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zfbmQ0gwoj69eyplasZv+fSVpBObd10VoEehjye/I2A=; b=Qk31qP97aFvsAo6dHaMgmix2E+tKT7SHrV79WXD22Ksc8D8tkIeXobS0T5ZmvVpKKgw6kS g23E93QmiXxbBCBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: Re: [PATCH v2 4/9] printk: Cleanup _braille_(un)register_console() wrappers In-Reply-To: <20260423130015.85175-5-pmladek@suse.com> References: <20260423130015.85175-1-pmladek@suse.com> <20260423130015.85175-5-pmladek@suse.com> Date: Fri, 15 May 2026 14:57:43 +0206 Message-ID: <87ik8o7s4g.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2026-04-23, Sashiko wrote: >> diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c >> index 06b43b678d6e..7b324329882f 100644 >> --- a/drivers/accessibility/braille/braille_console.c >> +++ b/drivers/accessibility/braille/braille_console.c >> @@ -360,12 +360,12 @@ int braille_register_console(struct console *console, int index, >> if (ret != 0) >> return ret; >> } >> - console->flags |= CON_ENABLED; >> + console->flags |= CON_ENABLED | CON_BRL; >> console->index = index; >> braille_co = console; >> register_keyboard_notifier(&keyboard_notifier_block); >> register_vt_notifier(&vt_notifier_block); >> - return 1; >> + return 0; >> } > > While reviewing this function, I noticed a pre-existing > regression. The printk subsystem relies on console_lock() to serialize > console setup against boot consoles that might be actively printing to > the same hardware port. For normal consoles, this synchronization is > handled explicitly: > > kernel/printk/printk.c:console_call_setup() { > ... > console_lock(); > err = newcon->setup(newcon, options); > console_unlock(); > ... > } > > However, it looks like braille_register_console() bypasses this > protection and directly invokes console->setup() just above this block > without acquiring console_lock(). > > Could this unprotected setup call cause a data race or hardware state > corruption if the underlying driver shares the hardware with an active > boot console? I do not know enough about braille consoles if they can also be early consoles, but it makes sense to synchronize the ->setup() callback. Something like this: --- a/drivers/accessibility/braille/braille_console.c +++ b/drivers/accessibility/braille/braille_console.c @@ -356,7 +356,9 @@ int braille_register_console(struct console *console, int index, if (braille_co) return -ENODEV; if (console->setup) { + console_lock(); ret = console->setup(console, console_options); + console_unlock(); if (ret != 0) return ret; } >> int braille_unregister_console(struct console *console) >> @@ -375,5 +375,6 @@ int braille_unregister_console(struct console *console) >> unregister_keyboard_notifier(&keyboard_notifier_block); >> unregister_vt_notifier(&vt_notifier_block); >> braille_co = NULL; >> - return 1; >> + console->flags &= ~(CON_ENABLED | CON_BRL); >> + return 0; >> } > > This also appears to be a pre-existing regression. The > unregister_keyboard_notifier() and unregister_vt_notifier() functions > remove callbacks from atomic notifier chains. Since atomic notifiers > execute their callbacks under RCU read lock, unregistering them only > unlinks the node without blocking for concurrent callbacks to finish. > > By immediately clearing the global braille_co pointer and returning, > could a concurrently executing keyboard_notifier_call that already > passed the braille_co check on another CPU cause a use-after-free or > null pointer dereference? > > Does this function need a synchronize_rcu() before returning to ensure > all callbacks have completed? atomic_notifier_chain_unregister() already calls synchronize_rcu() before returning, so no action is needed here. For this patch as it is: Reviewed-by: John Ogness (The console lock/unlock should be a separate patch.) John