Skip to content

Commit 25d27ed

Browse files
cladischtiwai
authored andcommitted
control: use reference-counted pid
Instead of storing the PID number, take a reference to the task's pid structure. This protects against duplicates due to PID overflows, and using pid_vnr() ensures that the PID returned by snd_ctl_elem_info() is correct as seen from the current namespace. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 31cef70 commit 25d27ed

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎include/sound/control.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ struct snd_kctl_event {
8686

8787
#define snd_kctl_event(n) list_entry(n, struct snd_kctl_event, list)
8888

89+
struct pid;
90+
8991
struct snd_ctl_file {
9092
struct list_head list; /* list of all control files */
9193
struct snd_card *card;
92-
pid_t pid;
94+
struct pid *pid;
9395
int prefer_pcm_subdevice;
9496
int prefer_rawmidi_subdevice;
9597
wait_queue_head_t change_sleep;

‎sound/core/control.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
7575
ctl->card = card;
7676
ctl->prefer_pcm_subdevice = -1;
7777
ctl->prefer_rawmidi_subdevice = -1;
78-
ctl->pid = current->pid;
78+
ctl->pid = get_pid(task_pid(current));
7979
file->private_data = ctl;
8080
write_lock_irqsave(&card->ctl_files_rwlock, flags);
8181
list_add_tail(&ctl->list, &card->ctl_files);
@@ -125,6 +125,7 @@ static int snd_ctl_release(struct inode *inode, struct file *file)
125125
control->vd[idx].owner = NULL;
126126
up_write(&card->controls_rwsem);
127127
snd_ctl_empty_read_queue(ctl);
128+
put_pid(ctl->pid);
128129
kfree(ctl);
129130
module_put(card->module);
130131
snd_card_file_remove(card, file);
@@ -672,7 +673,7 @@ static int snd_ctl_elem_info(struct snd_ctl_file *ctl,
672673
info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK;
673674
if (vd->owner == ctl)
674675
info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER;
675-
info->owner = vd->owner->pid;
676+
info->owner = pid_vnr(vd->owner->pid);
676677
} else {
677678
info->owner = -1;
678679
}

‎sound/core/pcm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
809809
card = pcm->card;
810810
read_lock(&card->ctl_files_rwlock);
811811
list_for_each_entry(kctl, &card->ctl_files, list) {
812-
if (kctl->pid == current->pid) {
812+
if (kctl->pid == task_pid(current)) {
813813
prefer_subdevice = kctl->prefer_pcm_subdevice;
814814
if (prefer_subdevice != -1)
815815
break;

‎sound/core/rawmidi.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
415415
subdevice = -1;
416416
read_lock(&card->ctl_files_rwlock);
417417
list_for_each_entry(kctl, &card->ctl_files, list) {
418-
if (kctl->pid == current->pid) {
418+
if (kctl->pid == task_pid(current)) {
419419
subdevice = kctl->prefer_rawmidi_subdevice;
420420
if (subdevice != -1)
421421
break;

0 commit comments

Comments
 (0)