mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: core: Mark some variables as __ro_after_init
@ 2026-05-24 16:29 Len Bao
  2026-05-25  7:32 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Len Bao @ 2026-05-24 16:29 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai; +Cc: Len Bao, linux-sound, linux-kernel

Some variables in the 'ALSA/core' are initialized only during the init
phase in the '__init' functions and never changed. So, mark them as
__ro_after_init to reduce the attack surface.

Signed-off-by: Len Bao <len.bao@gmx.us>
---
 sound/core/hrtimer.c              | 2 +-
 sound/core/oss/pcm_oss.c          | 4 ++--
 sound/core/rawmidi.c              | 4 ++--
 sound/core/seq/oss/seq_oss_init.c | 4 ++--
 sound/core/seq/seq_dummy.c        | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
index 9fcd1c03d..92c585f8e 100644
--- a/sound/core/hrtimer.c
+++ b/sound/core/hrtimer.c
@@ -20,7 +20,7 @@ MODULE_LICENSE("GPL");
 MODULE_ALIAS("snd-timer-" __stringify(SNDRV_TIMER_GLOBAL_HRTIMER));
 
 #define NANO_SEC	1000000000UL	/* 10^9 in sec */
-static unsigned int resolution;
+static unsigned int resolution __ro_after_init;
 
 struct snd_hrtimer {
 	struct snd_timer *timer;
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 33fd34f0d..402089e3f 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -32,8 +32,8 @@
 
 #define OSS_ALSAEMULVER		_SIOR ('M', 249, int)
 
-static int dsp_map[SNDRV_CARDS];
-static int adsp_map[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1};
+static int dsp_map[SNDRV_CARDS] __ro_after_init;
+static int adsp_map[SNDRV_CARDS] __ro_after_init = {[0 ... (SNDRV_CARDS-1)] = 1};
 static bool nonblock_open = 1;
 
 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Abramo Bagnara <abramo@alsa-project.org>");
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 3b1034a44..4dfd9d53e 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -28,8 +28,8 @@ MODULE_DESCRIPTION("Midlevel RawMidi code for ALSA.");
 MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_SND_OSSEMUL
-static int midi_map[SNDRV_CARDS];
-static int amidi_map[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1};
+static int midi_map[SNDRV_CARDS] __ro_after_init;
+static int amidi_map[SNDRV_CARDS] __ro_after_init = {[0 ... (SNDRV_CARDS-1)] = 1};
 module_param_array(midi_map, int, NULL, 0444);
 MODULE_PARM_DESC(midi_map, "Raw MIDI device number assigned to 1st OSS device.");
 module_param_array(amidi_map, int, NULL, 0444);
diff --git a/sound/core/seq/oss/seq_oss_init.c b/sound/core/seq/oss/seq_oss_init.c
index d3e6a8a8d..1aece46c8 100644
--- a/sound/core/seq/oss/seq_oss_init.c
+++ b/sound/core/seq/oss/seq_oss_init.c
@@ -27,8 +27,8 @@ static int maxqlen = SNDRV_SEQ_OSS_MAX_QLEN;
 module_param(maxqlen, int, 0444);
 MODULE_PARM_DESC(maxqlen, "maximum queue length");
 
-static int system_client = -1; /* ALSA sequencer client number */
-static int system_port = -1;
+static int system_client __ro_after_init = -1; /* ALSA sequencer client number */
+static int system_port __ro_after_init = -1;
 
 static int num_clients;
 static struct seq_oss_devinfo *client_table[SNDRV_SEQ_OSS_MAX_CLIENTS];
diff --git a/sound/core/seq/seq_dummy.c b/sound/core/seq/seq_dummy.c
index af45f328a..3fe0853aa 100644
--- a/sound/core/seq/seq_dummy.c
+++ b/sound/core/seq/seq_dummy.c
@@ -71,7 +71,7 @@ struct snd_seq_dummy_port {
 	int connect;
 };
 
-static int my_client = -1;
+static int my_client __ro_after_init = -1;
 
 /*
  * event input callback - just redirect events to subscribers
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: core: Mark some variables as __ro_after_init
  2026-05-24 16:29 [PATCH] ALSA: core: Mark some variables as __ro_after_init Len Bao
@ 2026-05-25  7:32 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-05-25  7:32 UTC (permalink / raw)
  To: Len Bao; +Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel

On Sun, 24 May 2026 18:29:13 +0200,
Len Bao wrote:
> 
> Some variables in the 'ALSA/core' are initialized only during the init
> phase in the '__init' functions and never changed. So, mark them as
> __ro_after_init to reduce the attack surface.
> 
> Signed-off-by: Len Bao <len.bao@gmx.us>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-25  7:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-24 16:29 [PATCH] ALSA: core: Mark some variables as __ro_after_init Len Bao
2026-05-25  7:32 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®