From patchwork Mon Jan 22 18:34:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 13526052 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2054.outbound.protection.outlook.com [40.92.89.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F93A3CF75; Mon, 22 Jan 2024 18:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.92.89.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705948405; cv=fail; b=UvZfCCxwc1xpTIv6Ct0hn+dlxcNNWrmcbpKiSv78lcXQ8ZafUi3jm22mUc6n7zgAF1bPFOutBevvXvFkym60TLe8rReg3QC2OzRLdpl/ixpKPB+BjphhnDZxiT20/LYav3ts8UC1uroEXZPNDQg3Yw8d0q/CtorFmay0/tx/N2M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705948405; c=relaxed/simple; bh=Ecvv2e9tns5KE1K6Jzhlh0/48ShEbOyp0+SrsRTurUk=; h=Message-ID:Date:Subject:From:To:References:In-Reply-To: Content-Type:MIME-Version; b=XFj+xEvB39R+szNcz0a1dZNOWKkeUsvRQxCwffYGqP+r/FscbDXulRofQ9YeCyPFUkQiwMylaPGwfDH7ancKtqpXXmPRQL9gE2DWE4mmBGVgIOD7+MGl0maZJnt3d/qBAmhcCaXEm6FIMZO0FUXUHHIszGVWfOQ7Y0WOP7CmbDE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hotmail.de; spf=pass smtp.mailfrom=hotmail.de; arc=fail smtp.client-ip=40.92.89.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hotmail.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hotmail.de ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jkOdTRwSE6+PIQIH4NYVDoXe90P+bT856Eg6iELqh+OIu0gWDikP0T19jJ1uPF1EWcvW0qVvgBwkNR1ZolQOupqP1B6QxbCJaltt4ocofTVUdE7BTBRfW2p3t/6knwFeEguQe+VLZN9y6Rr1XybMJwrgvoXC6CKydKmUadXo724EV7CDQqk/EEye5c4mtwKIc3uJTl8E/CDVINNH5rOb3En8YFX3k4gLa1tirXiZwLFRDw+H9AnLJskwhVXf1+yJjN4RR68g9TyKXwldQKzNlPEUqUXyC6WWXsejGY6XmHe/LN6XnFvwCIJL3LGOy9KHn4pXBOHJJ/A9flUuGJytAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WkLkCMGS0Kslf9FUZQDS7mtYKmevNVfHKUnmnRDYttI=; b=hbDK0LcsR7lawkduQtpnV63zn7KkogsCdg1k6N6x6Vl6Z2CyEVs6tBDZCTDRP0VHA4Cdf2hLNpUxtr4/UA7EKbugBjki2ggzoBinPM5qLa0n+5YbUFaPIKMnFRTUGh1J6Iy9ze2+uQiu/j/ILngLD1X5c2mXhez5m7gCXxKKMx6VBCvBjIHW9EF23EamhaxtH0+FaKe/QDms+UVTp6s7sC/xmKgGIE9bIJlYULEtf9LeFRTojTLLTG6bvN23nKs8ECqtkQgrze6DOyaOfJgYhzqfMdiVd+pju4UvLU0pP0WB+aHnsUPHPQOJapT0h1WRbiF8tzepiGrCLC/s9RJ1sw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) by AS8P193MB2111.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:44d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.32; Mon, 22 Jan 2024 18:33:22 +0000 Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::897e:cfd5:b29b:c611]) by AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::897e:cfd5:b29b:c611%6]) with mapi id 15.20.7202.031; Mon, 22 Jan 2024 18:33:22 +0000 Message-ID: Date: Mon, 22 Jan 2024 19:34:21 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v3] Fix error handling in begin_new_exec From: Bernd Edlinger To: Alexander Viro , Christian Brauner , Kees Cook , "Eric W. Biederman" , "linux-fsdevel@vger.kernel.org" , linux-mm@kvack.org, "linux-kernel@vger.kernel.org" , Andrew Morton References: Content-Language: en-US In-Reply-To: X-TMN: [FGDY1yHzdZc6FFv+Zt52tbL3ygr+LKpoOcr/HFmWL0igZMlPLETmsvVpaEXSjg6t] X-ClientProxiedBy: BE1P281CA0479.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:7e::23) To AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) X-Microsoft-Original-Message-ID: <1656ab24-26f4-4572-8bfc-663b533db78b@hotmail.de> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P193MB1285:EE_|AS8P193MB2111:EE_ X-MS-Office365-Filtering-Correlation-Id: 59987384-b291-4ad9-0ba0-08dc1b789cad X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1esE7zODz6EQvuNjGr+whIqrgLTYUoN/wLktW+mrjG5HP+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-8?q?tbu2ksghhS3zwWhIzo5IO7Agj0zaalL1gsTjfm/95h/UyhavO8ZZ4Mbt61ig=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-80ceb.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 59987384-b291-4ad9-0ba0-08dc1b789cad X-MS-Exchange-CrossTenant-AuthSource: AS8P193MB1285.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 18:33:22.0774 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P193MB2111 If get_unused_fd_flags() fails, the error handling is incomplete because bprm->cred is already set to NULL, and therefore free_bprm will not unlock the cred_guard_mutex. Note there are two error conditions which end up here, one before and one after bprm->cred is cleared. Fixes: b8a61c9e7b4a ("exec: Generic execfd support") Signed-off-by: Bernd Edlinger Acked-by: "Eric W. Biederman" --- fs/exec.c | 3 +++ 1 file changed, 3 insertions(+) v2: rebased to v6.7, retested and updated the commit message to fix a checkpatch.pl style nit about the too short sha1 hash in the Fixes: statement. And retained Eric's Acked-by from: https://lore.kernel.org/lkml/87mts2kcrm.fsf@disp2133/ v3: removed empty lines after Fixes: and Signed-off-by: header. Thanks Bernd. diff --git a/fs/exec.c b/fs/exec.c index 8cdd5b2dd09c..e88249a1ce07 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1409,6 +1409,9 @@ int begin_new_exec(struct linux_binprm * bprm) out_unlock: up_write(&me->signal->exec_update_lock); + if (!bprm->cred) + mutex_unlock(&me->signal->cred_guard_mutex); + out: return retval; }