From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B45D7CCFA13 for ; Sun, 9 Nov 2025 17:15:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21FF38E0006; Sun, 9 Nov 2025 12:15:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F7028E0002; Sun, 9 Nov 2025 12:15:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10CEE8E0006; Sun, 9 Nov 2025 12:15:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EF82F8E0002 for ; Sun, 9 Nov 2025 12:15:25 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 878A6140A39 for ; Sun, 9 Nov 2025 17:15:25 +0000 (UTC) X-FDA: 84091719810.12.01E10BB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id BD048A000C for ; Sun, 9 Nov 2025 17:15:23 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pgmrysgp; spf=pass (imf15.hostedemail.com: domain of oleg@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=oleg@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1762708523; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CH23Ki9EOjG++XfGf0hWyR5UKo/5fVuG3elhs2g375Y=; b=0PY8oJqeXK6d0sOoCJ3Dltw2/jcT+vkCt5gPzq2KUB2wRrPOaExGGKO3yvFGxEAfxMBdCf Yp7u6kceNtbSsIGdqUHHvl8OlYOCnZpovE83t0hnAg9phAKhJ0ERDiwyS5kV2plDhLl6io iKSjzOktNG/0jkglCTGvsi+lztrtlkg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1762708523; a=rsa-sha256; cv=none; b=J5SlC4zwNkqiLtoM/M81n7Ef1tsdVsxYy0/GpptllmHDLnQPKuC3jv6EuOp3KfkJ2b6HgS jRZqhLm2fT7COJKNhE46F+qmGHBI2GScKZ3vddMXMA9XyJN4EDdwlyHLG362HMjpOBQZ+r VgnNsappzQ+7Yi+XRO97fNyMywrjkeg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pgmrysgp; spf=pass (imf15.hostedemail.com: domain of oleg@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=oleg@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762708523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CH23Ki9EOjG++XfGf0hWyR5UKo/5fVuG3elhs2g375Y=; b=PgmrysgpS/nM6fmM6cgvEQM+wfMQZwOHA/wr+1NlUe/ZdirVEyL9pjyCdorcXkUHNRvhMx Hp5CMgpW68/q+nFSOMXiwPl5duVO9K3Z7DTdBNO+f4UZLSifPcK1Y6puN03TzIjf1kTdsC LNyRLvSMqHNF2UINfKrLZr3FgbhU5hM= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-hba6nzFHMM2ZSUG6656qEw-1; Sun, 09 Nov 2025 12:15:21 -0500 X-MC-Unique: hba6nzFHMM2ZSUG6656qEw-1 X-Mimecast-MFC-AGG-ID: hba6nzFHMM2ZSUG6656qEw_1762708516 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0CA8E180048E; Sun, 9 Nov 2025 17:15:15 +0000 (UTC) Received: from fedora (unknown [10.44.32.53]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id C8655180087B; Sun, 9 Nov 2025 17:14:53 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 9 Nov 2025 18:15:14 +0100 (CET) Date: Sun, 9 Nov 2025 18:14:52 +0100 From: Oleg Nesterov To: Bernd Edlinger , Linus Torvalds , Dmitry Levin Cc: Alexander Viro , Alexey Dobriyan , Kees Cook , Andy Lutomirski , Will Drewry , Christian Brauner , Andrew Morton , Michal Hocko , Serge Hallyn , James Morris , Randy Dunlap , Suren Baghdasaryan , Yafang Shao , Helge Deller , "Eric W. Biederman" , Adrian Reber , Thomas Gleixner , Jens Axboe , Alexei Starovoitov , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, tiozhang , Luis Chamberlain , "Paulo Alcantara (SUSE)" , Sergey Senozhatsky , Frederic Weisbecker , YueHaibing , Paul Moore , Aleksa Sarai , Stefan Roesch , Chao Yu , xu xin , Jeff Layton , Jan Kara , David Hildenbrand , Dave Chinner , Shuah Khan , Elena Reshetova , David Windsor , Mateusz Guzik , Ard Biesheuvel , "Joel Fernandes (Google)" , "Matthew Wilcox (Oracle)" , Hans Liljestrand , Penglei Jiang , Lorenzo Stoakes , Adrian Ratiu , Ingo Molnar , "Peter Zijlstra (Intel)" , Cyrill Gorcunov , Eric Dumazet Subject: [RFC PATCH 1/3] exec: make setup_new_exec() return int Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BD048A000C X-Stat-Signature: oc1x8zooncu83sfmngae6fhnaf6mr4yx X-Rspam-User: X-HE-Tag: 1762708523-270355 X-HE-Meta: U2FsdGVkX1/5nvJEunuXJ1OUyGVsaoysIH7RQLrzCF3yWt97eVyXJjEMHa8XOpiRKcxYRu/xhXFCzI6HTaSRel4cMXSG2ukWN/qnzDRGlrhLqL6F5QhrYLJDkqGdJWKfjHmWpzH+pzsWb2iiaS8Gruka/ArvaRtzP7CuOV8JAaGOrSC0VJABYrxcJiIs0jW6UUdf9FfvqwP5z6y2scD9eaLcMEobuxNV3zfRvb/ehYWpZTvSR+7HvaQyMFsPM3RpoR8eKVMx77aVAm6TXfuTKpKOPlC4HS/U16kpNAhn3sf9baQbVa0qx5FjIMEekArSFwPoKLg4cXRIYurTCZy6odEPrdoiexKFJDCc3ctY1bRtgFjnrmRiNMB/c8RX/z5vKbC9+YCz3ZhehOeX+VtuEeL+rCXHQHTVJ/XMW0yWNbNse+Gw1h9WiHKQxK6shFfLm2cuK5kEsxYdroQcWPBILc+zeaUHO+NmulJ3lMOtGWdE2varXFFkRwW+4XdUVIa5k2SBft4y7m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precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Preparation. After the next change setup_new_exec() can fail. Signed-off-by: Oleg Nesterov --- fs/binfmt_elf.c | 4 +++- fs/binfmt_elf_fdpic.c | 4 +++- fs/binfmt_flat.c | 4 +++- fs/exec.c | 4 +++- include/linux/binfmts.h | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index e4653bb99946..8a38689ae4b0 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1021,7 +1021,9 @@ static int load_elf_binary(struct linux_binprm *bprm) if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space) current->flags |= PF_RANDOMIZE; - setup_new_exec(bprm); + retval = setup_new_exec(bprm); + if (retval) + goto out_free_dentry; /* Do this so that we can load the interpreter, if need be. We will change some of these later */ diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 48fd2de3bca0..7ad98b8132fc 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -351,7 +351,9 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) if (elf_read_implies_exec(&exec_params.hdr, executable_stack)) current->personality |= READ_IMPLIES_EXEC; - setup_new_exec(bprm); + retval = setup_new_exec(bprm); + if (retval) + goto error; set_binfmt(&elf_fdpic_format); diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index b5b5ca1a44f7..78e9ca128ea7 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -512,7 +512,9 @@ static int load_flat_file(struct linux_binprm *bprm, /* OK, This is the point of no return */ set_personality(PER_LINUX_32BIT); - setup_new_exec(bprm); + ret = setup_new_exec(bprm); + if (ret) + goto err; /* * calculate the extra space we need to map in diff --git a/fs/exec.c b/fs/exec.c index 6b70c6726d31..136a7ab5d91c 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1321,7 +1321,7 @@ void would_dump(struct linux_binprm *bprm, struct file *file) } EXPORT_SYMBOL(would_dump); -void setup_new_exec(struct linux_binprm * bprm) +int setup_new_exec(struct linux_binprm * bprm) { /* Setup things that can depend upon the personality */ struct task_struct *me = current; @@ -1337,6 +1337,8 @@ void setup_new_exec(struct linux_binprm * bprm) me->mm->task_size = TASK_SIZE; up_write(&me->signal->exec_update_lock); mutex_unlock(&me->signal->cred_guard_mutex); + + return 0; } EXPORT_SYMBOL(setup_new_exec); diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h index 65abd5ab8836..678b7525ac5a 100644 --- a/include/linux/binfmts.h +++ b/include/linux/binfmts.h @@ -123,7 +123,7 @@ extern void unregister_binfmt(struct linux_binfmt *); extern int __must_check remove_arg_zero(struct linux_binprm *); extern int begin_new_exec(struct linux_binprm * bprm); -extern void setup_new_exec(struct linux_binprm * bprm); +extern int setup_new_exec(struct linux_binprm * bprm); extern void finalize_exec(struct linux_binprm *bprm); extern void would_dump(struct linux_binprm *, struct file *); -- 2.25.1.362.g51ebf55