]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - sound/pci/hda/hda_hwdep.c
ALSA: hda: Hardening for potential Spectre v1
[mirror_ubuntu-bionic-kernel.git] / sound / pci / hda / hda_hwdep.c
index 57df06e76968ac4abd0f00b3005c416af256cb7b..cc009a4a3d1d206a8480a506894a59c0226c2e9a 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/compat.h>
+#include <linux/nospec.h>
 #include <sound/core.h>
 #include "hda_codec.h"
 #include "hda_local.h"
@@ -51,7 +52,16 @@ static int get_wcap_ioctl(struct hda_codec *codec,
        
        if (get_user(verb, &arg->verb))
                return -EFAULT;
-       res = get_wcaps(codec, verb >> 24);
+       /* open-code get_wcaps(verb>>24) with nospec */
+       verb >>= 24;
+       if (verb < codec->core.start_nid ||
+           verb >= codec->core.start_nid + codec->core.num_nodes) {
+               res = 0;
+       } else {
+               verb -= codec->core.start_nid;
+               verb = array_index_nospec(verb, codec->core.num_nodes);
+               res = codec->wcaps[verb];
+       }
        if (put_user(res, &arg->res))
                return -EFAULT;
        return 0;