Commit 33927f3
Al Viro
habanalabs: fix UAF in export_dmabuf()
As soon as we'd inserted a file reference into descriptor table, another
thread could close it. That's fine for the case when all we are doing is
returning that descriptor to userland (it's a race, but it's a userland
race and there's nothing the kernel can do about it). However, if we
follow fd_install() with any kind of access to objects that would be
destroyed on close (be it the struct file itself or anything destroyed
by its ->release()), we have a UAF.
dma_buf_fd() is a combination of reserving a descriptor and fd_install().
habanalabs export_dmabuf() calls it and then proceeds to access the
objects destroyed on close. In particular, it grabs an extra reference to
another struct file that will be dropped as part of ->release() for ours;
that "will be" is actually "might have already been".
Fix that by reserving descriptor before anything else and do fd_install()
only when everything had been set up. As a side benefit, we no longer
have the failure exit with file already created, but reference to
underlying file (as well as ->dmabuf_export_cnt, etc.) not grabbed yet;
unlike dma_buf_fd(), fd_install() can't fail.
Fixes: db1a8dd ("habanalabs: add support for dma-buf exporter")
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>1 parent d7b8f8e commit 33927f3
1 file changed
+7
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1829 | 1829 | | |
1830 | 1830 | | |
1831 | 1831 | | |
1832 | | - | |
1833 | | - | |
1834 | | - | |
1835 | 1832 | | |
1836 | 1833 | | |
1837 | 1834 | | |
| |||
1859 | 1856 | | |
1860 | 1857 | | |
1861 | 1858 | | |
1862 | | - | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
1863 | 1865 | | |
1864 | 1866 | | |
1865 | 1867 | | |
| |||
1872 | 1874 | | |
1873 | 1875 | | |
1874 | 1876 | | |
1875 | | - | |
1876 | | - | |
1877 | | - | |
1878 | | - | |
1879 | | - | |
1880 | | - | |
1881 | | - | |
1882 | 1877 | | |
1883 | 1878 | | |
1884 | 1879 | | |
| |||
1890 | 1885 | | |
1891 | 1886 | | |
1892 | 1887 | | |
| 1888 | + | |
1893 | 1889 | | |
1894 | 1890 | | |
1895 | | - | |
1896 | | - | |
1897 | | - | |
1898 | | - | |
1899 | | - | |
1900 | 1891 | | |
1901 | 1892 | | |
1902 | 1893 | | |
| |||
0 commit comments