Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

switch {alloc,free}_bprm() to CLASS()

All linux_binprm instances come from alloc_bprm() and are unconditionally
destroyed by free_bprm() in the end of the same scope. IOW, CLASS()
machinery is a decent fit for those.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 0697b4f4 194c760b

+21 -27
+21 -27
fs/exec.c
··· 1465 1465 return ERR_PTR(retval); 1466 1466 } 1467 1467 1468 + DEFINE_CLASS(bprm, struct linux_binprm *, if (!IS_ERR(_T)) free_bprm(_T), 1469 + alloc_bprm(fd, name, flags), int fd, struct filename *name, int flags) 1470 + 1468 1471 int bprm_change_interp(const char *interp, struct linux_binprm *bprm) 1469 1472 { 1470 1473 /* If a binfmt changed the interp, free it first. */ ··· 1782 1779 struct user_arg_ptr envp, 1783 1780 int flags) 1784 1781 { 1785 - struct linux_binprm *bprm; 1786 1782 int retval; 1787 1783 1788 1784 /* ··· 1798 1796 * further execve() calls fail. */ 1799 1797 current->flags &= ~PF_NPROC_EXCEEDED; 1800 1798 1801 - bprm = alloc_bprm(fd, filename, flags); 1799 + CLASS(bprm, bprm)(fd, filename, flags); 1802 1800 if (IS_ERR(bprm)) 1803 1801 return PTR_ERR(bprm); 1804 1802 1805 1803 retval = count(argv, MAX_ARG_STRINGS); 1806 1804 if (retval < 0) 1807 - goto out_free; 1805 + return retval; 1808 1806 bprm->argc = retval; 1809 1807 1810 1808 retval = count(envp, MAX_ARG_STRINGS); 1811 1809 if (retval < 0) 1812 - goto out_free; 1810 + return retval; 1813 1811 bprm->envc = retval; 1814 1812 1815 1813 retval = bprm_stack_limits(bprm); 1816 1814 if (retval < 0) 1817 - goto out_free; 1815 + return retval; 1818 1816 1819 1817 retval = copy_string_kernel(bprm->filename, bprm); 1820 1818 if (retval < 0) 1821 - goto out_free; 1819 + return retval; 1822 1820 bprm->exec = bprm->p; 1823 1821 1824 1822 retval = copy_strings(bprm->envc, envp, bprm); 1825 1823 if (retval < 0) 1826 - goto out_free; 1824 + return retval; 1827 1825 1828 1826 retval = copy_strings(bprm->argc, argv, bprm); 1829 1827 if (retval < 0) 1830 - goto out_free; 1828 + return retval; 1831 1829 1832 1830 /* 1833 1831 * When argv is empty, add an empty string ("") as argv[0] to ··· 1838 1836 if (bprm->argc == 0) { 1839 1837 retval = copy_string_kernel("", bprm); 1840 1838 if (retval < 0) 1841 - goto out_free; 1839 + return retval; 1842 1840 bprm->argc = 1; 1843 1841 1844 1842 pr_warn_once("process '%s' launched '%s' with NULL argv: empty string added\n", 1845 1843 current->comm, bprm->filename); 1846 1844 } 1847 1845 1848 - retval = bprm_execve(bprm); 1849 - out_free: 1850 - free_bprm(bprm); 1851 - return retval; 1846 + return bprm_execve(bprm); 1852 1847 } 1853 1848 1854 1849 int kernel_execve(const char *kernel_filename, 1855 1850 const char *const *argv, const char *const *envp) 1856 1851 { 1857 - struct linux_binprm *bprm; 1858 - int fd = AT_FDCWD; 1859 1852 int retval; 1860 1853 1861 1854 /* It is non-sense for kernel threads to call execve */ ··· 1858 1861 return -EINVAL; 1859 1862 1860 1863 CLASS(filename_kernel, filename)(kernel_filename); 1861 - bprm = alloc_bprm(fd, filename, 0); 1864 + CLASS(bprm, bprm)(AT_FDCWD, filename, 0); 1862 1865 if (IS_ERR(bprm)) 1863 1866 return PTR_ERR(bprm); 1864 1867 1865 1868 retval = count_strings_kernel(argv); 1866 1869 if (WARN_ON_ONCE(retval == 0)) 1867 - retval = -EINVAL; 1870 + return -EINVAL; 1868 1871 if (retval < 0) 1869 - goto out_free; 1872 + return retval; 1870 1873 bprm->argc = retval; 1871 1874 1872 1875 retval = count_strings_kernel(envp); 1873 1876 if (retval < 0) 1874 - goto out_free; 1877 + return retval; 1875 1878 bprm->envc = retval; 1876 1879 1877 1880 retval = bprm_stack_limits(bprm); 1878 1881 if (retval < 0) 1879 - goto out_free; 1882 + return retval; 1880 1883 1881 1884 retval = copy_string_kernel(bprm->filename, bprm); 1882 1885 if (retval < 0) 1883 - goto out_free; 1886 + return retval; 1884 1887 bprm->exec = bprm->p; 1885 1888 1886 1889 retval = copy_strings_kernel(bprm->envc, envp, bprm); 1887 1890 if (retval < 0) 1888 - goto out_free; 1891 + return retval; 1889 1892 1890 1893 retval = copy_strings_kernel(bprm->argc, argv, bprm); 1891 1894 if (retval < 0) 1892 - goto out_free; 1895 + return retval; 1893 1896 1894 - retval = bprm_execve(bprm); 1895 - out_free: 1896 - free_bprm(bprm); 1897 - return retval; 1897 + return bprm_execve(bprm); 1898 1898 } 1899 1899 1900 1900 void set_binfmt(struct linux_binfmt *new)