Commit 978ffcb
committed
execve: open the executable file before doing anything else
No point in allocating a new mm, counting arguments and environment
variables etc if we're just going to return ENOENT.
This patch does expose the fact that 'do_filp_open()' that execve() uses
is still unnecessarily expensive in the failure case, because it
allocates the 'struct file *' early, even if the path lookup (which is
heavily optimized) fails.
So that remains an unnecessary cost in the "no such executable" case,
but it's a separate issue. Regardless, I do not want to do _both_ a
filename_lookup() and a later do_filp_open() like the origin patch by
Josh Triplett did in [1].
Reported-by: Josh Triplett <josh@joshtriplett.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Link: https://lore.kernel.org/lkml/5c7333ea4bec2fad1b47a8fa2db7c31e4ffc4f14.1663334978.git.josh@joshtriplett.org/ [1]
Link: https://lore.kernel.org/lkml/202209161637.9EDAF6B18@keescook/
Link: https://lore.kernel.org/lkml/CAHk-=wgznerM-xs+x+krDfE7eVBiy_HOam35rbsFMMOwvYuEKQ@mail.gmail.com/
Link: https://lore.kernel.org/lkml/CAHk-=whf9qLO8ipps4QhmS0BkM8mtWJhvnuDSdtw5gFjhzvKNA@mail.gmail.com/
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>1 parent e5075d8 commit 978ffcb
1 file changed
+35
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1508 | 1508 | | |
1509 | 1509 | | |
1510 | 1510 | | |
1511 | | - | |
| 1511 | + | |
1512 | 1512 | | |
1513 | | - | |
| 1513 | + | |
| 1514 | + | |
1514 | 1515 | | |
1515 | | - | |
1516 | | - | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
1517 | 1529 | | |
1518 | 1530 | | |
1519 | 1531 | | |
| |||
1526 | 1538 | | |
1527 | 1539 | | |
1528 | 1540 | | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
1529 | 1553 | | |
1530 | 1554 | | |
1531 | 1555 | | |
1532 | 1556 | | |
1533 | 1557 | | |
1534 | | - | |
1535 | | - | |
1536 | | - | |
| 1558 | + | |
| 1559 | + | |
1537 | 1560 | | |
1538 | 1561 | | |
1539 | 1562 | | |
1540 | | - | |
1541 | 1563 | | |
1542 | 1564 | | |
1543 | 1565 | | |
| |||
1807 | 1829 | | |
1808 | 1830 | | |
1809 | 1831 | | |
1810 | | - | |
1811 | | - | |
| 1832 | + | |
1812 | 1833 | | |
1813 | | - | |
1814 | 1834 | | |
1815 | 1835 | | |
1816 | 1836 | | |
| |||
1826 | 1846 | | |
1827 | 1847 | | |
1828 | 1848 | | |
1829 | | - | |
1830 | | - | |
1831 | | - | |
1832 | | - | |
1833 | | - | |
1834 | 1849 | | |
1835 | 1850 | | |
1836 | | - | |
1837 | | - | |
1838 | | - | |
1839 | | - | |
1840 | | - | |
1841 | | - | |
1842 | | - | |
1843 | | - | |
1844 | | - | |
1845 | | - | |
1846 | | - | |
1847 | | - | |
1848 | | - | |
1849 | 1851 | | |
1850 | 1852 | | |
1851 | 1853 | | |
| |||
1875 | 1877 | | |
1876 | 1878 | | |
1877 | 1879 | | |
1878 | | - | |
1879 | 1880 | | |
1880 | 1881 | | |
1881 | 1882 | | |
| |||
1910 | 1911 | | |
1911 | 1912 | | |
1912 | 1913 | | |
1913 | | - | |
| 1914 | + | |
1914 | 1915 | | |
1915 | 1916 | | |
1916 | 1917 | | |
| |||
1959 | 1960 | | |
1960 | 1961 | | |
1961 | 1962 | | |
1962 | | - | |
| 1963 | + | |
1963 | 1964 | | |
1964 | 1965 | | |
1965 | 1966 | | |
| |||
1984 | 1985 | | |
1985 | 1986 | | |
1986 | 1987 | | |
1987 | | - | |
| 1988 | + | |
1988 | 1989 | | |
1989 | 1990 | | |
1990 | 1991 | | |
| |||
2019 | 2020 | | |
2020 | 2021 | | |
2021 | 2022 | | |
2022 | | - | |
| 2023 | + | |
2023 | 2024 | | |
2024 | 2025 | | |
2025 | 2026 | | |
| |||
0 commit comments