ALSA: emu10k1: move patch loader assertions into low-level functions
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>
Sat, 6 Apr 2024 06:48:21 +0000 (08:48 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sun, 7 Apr 2024 06:35:48 +0000 (08:35 +0200)
Convert some checks in snd_emu10k1_sample_new() back into assertions (as
they were prior to da3cec35dd (ALSA: Kill snd_assert() in sound/pci/*,
2008-08-08)), and move them into the low-level memory access functions
they protect.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Message-ID: <20240406064830.1029573-9-oswald.buddenhagen@gmx.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/emu10k1/emu10k1_patch.c
sound/pci/emu10k1/memory.c

index 47d69a0e44bc6019b027cfbba24d3bba5234dfdc..55bb60d31fe4539000b9811531ebdf20169ac352 100644 (file)
@@ -65,8 +65,6 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
        size = BLANK_HEAD_SIZE;
        if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS))
                size *= 2;
-       if (offset + size > blocksize)
-               return -EINVAL;
        snd_emu10k1_synth_bzero(emu, sp->block, offset, size);
        offset += size;
 
@@ -74,8 +72,6 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
        size = sp->v.size;
        if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS))
                size *= 2;
-       if (offset + size > blocksize)
-               return -EINVAL;
        if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size)) {
                snd_emu10k1_synth_free(emu, sp->block);
                sp->block = NULL;
index 20b07117574b4bcbf4496745e3fc198ff5e4c82f..fc944440415164cf9afc8a5def9758faea9446cd 100644 (file)
@@ -574,6 +574,9 @@ int snd_emu10k1_synth_bzero(struct snd_emu10k1 *emu, struct snd_util_memblk *blk
        void *ptr;
        struct snd_emu10k1_memblk *p = (struct snd_emu10k1_memblk *)blk;
 
+       if (snd_BUG_ON(offset + size > p->mem.size))
+               return -EFAULT;
+
        offset += blk->offset & (PAGE_SIZE - 1);
        end_offset = offset + size;
        page = get_aligned_page(offset);
@@ -604,6 +607,9 @@ int snd_emu10k1_synth_copy_from_user(struct snd_emu10k1 *emu, struct snd_util_me
        void *ptr;
        struct snd_emu10k1_memblk *p = (struct snd_emu10k1_memblk *)blk;
 
+       if (snd_BUG_ON(offset + size > p->mem.size))
+               return -EFAULT;
+
        offset += blk->offset & (PAGE_SIZE - 1);
        end_offset = offset + size;
        page = get_aligned_page(offset);