From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E429266B6B for ; Fri, 12 Dec 2025 14:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765548649; cv=none; b=JGLJiqd4h5aQG463qwOkcCX3vaLOrMTNaMaky5/58hK0Nd4niKDa4DVBIrko2z8yFpPSzzvK6oiQzq61AheeiDm7NEFrq3f+LvmszIVHe7jr3AOmy8EBjKzq1rVg0Yhspj2eLzgTtnL9PNhLJmHpef3dRYJQ/sJl5eCgKbyeKgw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765548649; c=relaxed/simple; bh=S+7lcJ1FbbQOBq5zQ6GDAi+86cfV5KndWy7a8vuPmkk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V0m+hZOjoMxVG/KtvPMv5eFBf0gvRcnMNEydAXutlWXTMPC7pmgAg90juHPnqsFKW+zEdWyKDZfEauM/bk0VrkigdIWPXSd7ZoPoNYbKI3Kwsf4y0OhNr1laxgldZnpmPmVQUBJts0EmbrTDxNDMVo2jBFDNqBn5VhTvZq8e2X0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=J0f7n45v; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="J0f7n45v" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4775e891b5eso6178475e9.2 for ; Fri, 12 Dec 2025 06:10:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765548646; x=1766153446; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ltqENdrpFqpNOFjZUAuq6+u1l4jbedkcCyl7O+CrBh4=; b=J0f7n45vwzv8vr11/i2QHfAzws+tkWkIn1DKvC5UfZeWc6MeCMWII8RaXbPwbIy+0A NiM49TUO+s2hSurfKaX/HOyygtkTDQctD8WFIslYIYpPRXw2YK6owVtF+5/p8L1DyQ8c 8MrNsE4nbdPpBZKhjvqNu9wSKeQOJFi1Fy9ZBIdq7AbZVpX9yRRscWWuPfoF7DGpxtJm 71f6LbiSivyt0+isEHmoYGQS6qqWIxH2gcKG/h+vqqQeA5eemiy77cqmdtVizizANQYU oToWwCXDMdz2rJNi+Rv3ZAY0sfLXYmeLwxu25G4VP+psU64ahS4ue4DUdeQOmzbyB6Jd 1JZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765548646; x=1766153446; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ltqENdrpFqpNOFjZUAuq6+u1l4jbedkcCyl7O+CrBh4=; b=m4Qa5eRYsFWjzDAt4QaAIG1Rs5qQ2w2HLiYTB79Fn5/iDndMPNGXkYPIvwYd7OzSbv E9UF/mNtnieLLvWlBWsmMyzN13QXl+YHpAZDY5z5ZBkigE8gGwZIWWfUWkySga0PCTXd jD3e8GAlNNK81WUduG6kkAFjH612hFLcPCIm3nVrfGvj6GGZq78QWhCxMQl75t9keOtn Y/jJRIZ28eEUTE6Qf/PU72KlpxoBJSWGOcRKDhrcLbpsQnRZ82/QzluXKU7slaagAVO/ jx/SzHnYX3JLXexMWIYnwG1D5gW54CRmzD2K/XemX+2nc5wOvFPqfvwuZRl065Ph5rIf ZCPw== X-Gm-Message-State: AOJu0Yxg5phwaFZW+YLv+4Ypqanbvc55w7GiIyz0aaegFpqCCDeKVySQ 4mFhb0DhcxJKU6tdSH/4fuWaoFqDVgzckIC83ByRPAa2pEC8g0PYTfTJqyjRsBcXgKE= X-Gm-Gg: AY/fxX4wQNDndHC7NxQdA9qV6Y3kmIK2k9KOjrl1fLAl69qTETNCjxff1s81A/QZIcT NaWGVm5wCzAOfJuv2bnpt9L7PNf4JImc15qc6DD7PIzF7nd3pC4Wpu/3XHXSdBhM3p33JxaeDyv Hj7f39sGL0wRKVj5yklH21RPXKjtNPH39bBkofvlBrgtAV3qEhXUv8keWE5HAg2mjldP1XxODdz ZPQDs4llaJRDHjakOXbpc4hwysRDtWEMN6uYPe8SJreYUGF8LfUpF5hteLvdMshYu92LZVxvCfH m3yFYQZ3feRb7+8M4WMhmVlEW7/z3eEKwGWj2uJSBEe7FI7di49qUlJcm8qtncAV0+kHpGjY7sG 9HQTmg4F9LozPyrhhhRx9gz8pGU/kCgaeHmG0iVduZQ0ijvPNDCNxBbHzuHgMsTRCmEuLNKkbmz eLEoKBarBWBZt6tg== X-Google-Smtp-Source: AGHT+IFpDgBPY8k0WZp7eWZaqsRaDVQ+/UmcC7iOoBFoJT4Nq2IJpK9TAed4+nEJB6Pqh8wcJNOBjQ== X-Received: by 2002:a05:600c:628d:b0:477:632c:5b91 with SMTP id 5b1f17b1804b1-47a8f8d21f7mr28715805e9.16.1765548645777; Fri, 12 Dec 2025 06:10:45 -0800 (PST) Received: from pathway ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a8f4ae4d3sm12457735e9.5.2025.12.12.06.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 06:10:45 -0800 (PST) Date: Fri, 12 Dec 2025 15:10:43 +0100 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: Re: [PATCH v8 15/21] printk: sysrq: Clamp console loglevel to valid range Message-ID: References: <77d1f4e89cb69b8eb45e118cea1383a8f577f704.1764272407.git.chris@chrisdown.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <77d1f4e89cb69b8eb45e118cea1383a8f577f704.1764272407.git.chris@chrisdown.name> On Fri 2025-11-28 03:44:10, Chris Down wrote: > The sysrq loglevel handler (keys 0-9) directly assigns the numeric key > value to console_loglevel without any validation. This creates an > inconsistency with other interfaces: the new kernel.console_loglevel > sysctl, the per-console sysfs loglevel interface, and the > SYSLOG_ACTION_CONSOLE_LEVEL syslog command all clamp or reject values > outside the valid range. > > In particular, sysrq 0 sets console_loglevel to 0 (LOGLEVEL_EMERG), > which is problematic because: > > 1. LOGLEVEL_EMERG (0) is reserved for emergency messages that should > always reach all consoles. Setting console_loglevel to 0 would mean > only KERN_EMERG messages print, which is likely never intended. > > 2. The per-console loglevel infrastructure explicitly rejects level 0 > for this reason, creating an inconsistency where sysrq can set a > value that other interfaces refuse. > > 3. CONSOLE_LOGLEVEL_MIN is defined as 1, indicating the minimum valid > console loglevel, yet sysrq ignores this. > > Similarly, sysrq 9 sets console_loglevel to 9, which is above > LOGLEVEL_DEBUG (7) and serves no useful purpose since no messages have > a level that high. > > Use console_clamp_loglevel() to clamp the requested loglevel to the > valid range [1, 8]. This ensures consistent behaviour across all > loglevel-setting interfaces. > > Signed-off-by: Chris Down Great catch! Feel free to use: Reviewed-by: Petr Mladek See a nit below. > --- a/include/linux/printk.h > +++ b/include/linux/printk.h > @@ -65,6 +65,7 @@ static inline const char *printk_skip_headers(const char *buffer) > int match_devname_and_update_preferred_console(const char *match, > const char *name, > const short idx); > +int console_clamp_loglevel(int level); It makes the same declaration in kernel/printk/internal.h redundant and it can be removed there. > extern int console_printk[]; > Best Regards, Petr