]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
RDMA/qib: Validate ->show()/store() callbacks before calling them
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 7 Nov 2019 03:20:25 +0000 (08:50 +0530)
committerMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
Fri, 17 Jan 2020 17:23:32 +0000 (14:23 -0300)
BugLink: https://bugs.launchpad.net/bugs/1856334
commit 7ee23491b39259ae83899dd93b2a29ef0f22f0a7 upstream.

The permissions of the read-only or write-only sysfs files can be
changed (as root) and the user can then try to read a write-only file or
write to a read-only file which will lead to kernel crash here.

Protect against that by always validating the show/store callbacks.

Link: https://lore.kernel.org/r/d45cc26361a174ae12dbb86c994ef334d257924b.1573096807.git.viresh.kumar@linaro.org
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Connor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/infiniband/hw/qib/qib_sysfs.c

index 905206a0c2d5aae66b4296d232daf9f1ec0e85f7..d4f5e8cd438dec77186e00c4588676580f52d9c4 100644 (file)
@@ -301,6 +301,9 @@ static ssize_t qib_portattr_show(struct kobject *kobj,
        struct qib_pportdata *ppd =
                container_of(kobj, struct qib_pportdata, pport_kobj);
 
+       if (!pattr->show)
+               return -EIO;
+
        return pattr->show(ppd, buf);
 }
 
@@ -312,6 +315,9 @@ static ssize_t qib_portattr_store(struct kobject *kobj,
        struct qib_pportdata *ppd =
                container_of(kobj, struct qib_pportdata, pport_kobj);
 
+       if (!pattr->store)
+               return -EIO;
+
        return pattr->store(ppd, buf, len);
 }