From patchwork Wed Dec 11 09:21:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13903246 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]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36A85E7717D for ; Wed, 11 Dec 2024 09:21:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C4D08D0015; Wed, 11 Dec 2024 04:21:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 974988D0013; Wed, 11 Dec 2024 04:21:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83BD18D0015; Wed, 11 Dec 2024 04:21:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 63FC18D0013 for ; Wed, 11 Dec 2024 04:21:47 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BBB0D1208A2 for ; Wed, 11 Dec 2024 09:21:46 +0000 (UTC) X-FDA: 82882134468.09.03D9710 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by imf06.hostedemail.com (Postfix) with ESMTP id BFDF718001B for ; Wed, 11 Dec 2024 09:21:28 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=aAGNLst1; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf06.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.128.43 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733908894; 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: references:dkim-signature; bh=0DLsS1CyBK/Moo7ZlFFxPYN1OuvOVl2Ay8BHF7WI398=; b=HyowYTuql+Vo072+I1npxLkOy9b9tWlUlW4nT3ianSrnGQ1IgDWJ1mEdQVz5+KL07bxBqc T0lPZhaYW3MQ+NP7fcnmsbbUyzNSGVfqRtXOm+QFtLtd3KB2t/aNn8Q+sY/EMXTvNYkEra 4WOk6PPDxkQkjeU9K23nI29nfoq56Sw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733908894; a=rsa-sha256; cv=none; b=OGUii3wDFS2RFwdHtLhxWbGaAn7XOZQrxyIW5wA+rTy4y08rMdI72ium7I3piQOa3ttHhW a++BgqdQ9tysVxRblrjS9egqXIF6+q8tOGXFhQyVCF/5lFs4qf4WmaeDdwWUeCW3YwKzPy y+yW9zZw+eEd1oK/f4aBJvm0OFFTNyQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=aAGNLst1; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf06.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.128.43 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-434fef8203fso16510415e9.1 for ; Wed, 11 Dec 2024 01:21:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733908903; x=1734513703; darn=kvack.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=0DLsS1CyBK/Moo7ZlFFxPYN1OuvOVl2Ay8BHF7WI398=; b=aAGNLst17RFCANiwq5wyePjKeXRDcHafvYGxwcEkXFe2lg3ktCdZ95eCQX/1bXHhy7 oUbWQutXzcEwDXlfY0pYaYPVot96vqhp90yJMbWlkXYFtDPaX+x2AqM+iMOmV0cxPJy1 ZfuBLu9cwndZWNZRcyxeXylZ7+2tenHOUMAtq04wltkVnX6OQv+xuzjtrdrVsvOo85Qj 4u6IzC5PVQ+LiLI/0DIEtOeuDuCbgSGQGwZ1btW4FlKB2EKfvXVgQg3MAhq50UazvqG8 fM5mHARhDEkvr3glJi77U9o2KrSQMrMiSUUhviijzSNhZPKD1QKrZpWL2PXOFbMlIPp1 HMYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733908903; x=1734513703; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0DLsS1CyBK/Moo7ZlFFxPYN1OuvOVl2Ay8BHF7WI398=; b=kuTbH0N+xbqza4DgTsyiTp29h/mctQymvCk6qjA6s/MjYFKxqEhhDrpFDtGz1WMs22 H7BoHH9dtNtkZOgr5iunxolHyxqdHV12dqSjcsNbqKU1L54CXPEVLbOt5JFVtbwn59wI cmhzpnEVCv7RIvja57WQcqQo+3YGL24B2pa7/tXPZG2jVOyNUnrJe/E1rkp0JR7ZeZzW 0IOVoEeqwSATWPMuCLOXyaBC1M223DIw7SJnWWFAyB1HxTqaAbDVAVyV6wUFN+vdU1vA YPEc3121Q3bfcTzCXCwYAeN0FwYSCoKgOmHAI376W+VET++PgYGkOlq8xzaV/wAAgatR 9tvg== X-Forwarded-Encrypted: i=1; AJvYcCVbq0mSDYuyy01jN6Qv6qcY6XxBh7KV+xgeFfJFwvfuQWe7SD0cwjTzI9NnHsZp/zQumTiJUll4MA==@kvack.org X-Gm-Message-State: AOJu0YxOJCLuCKSaxTgF04lp80Ws5IyP4YDOfDE1h1f9dsBGl6bqhNbZ mFQdxUW68ykVOfUln9BU3QYOM7pknDqMJaLLDLz6VgNk6943oB/Td1ZjYo9ZfAU= X-Gm-Gg: ASbGncsPsQgHHQ13uDjGpKU/rUW6jNxk05XzDPstViZMeFeglixuVHo5nPNUKqmfg6y S7M//2mPXY0EKVKWKurVYAdmELC1bSw9ciPEgQZZxg1xj+mHgcKINkLJzyKi9CWeNWbpMsDQ2ib BiMR1YkMED5ExELTdcdpcOrfFGw7Prm/Eo0YJejQGY+x33v6Ixb9mp+83nm0AgFLqT5GqGMxWJq atmcae8uw5lmzBIx5c/pW72wMPNWjQckI49FB8ITLNZCGTb3hpyqUGIy/s= X-Google-Smtp-Source: AGHT+IGPYeRitgpKtJOXyRZn4COfRNxYFbNQZ+CVZoA5uGWAMNXxGSSG6fybBnG6Xshn8ee/kKy9Ig== X-Received: by 2002:a05:600c:1907:b0:434:a902:97cd with SMTP id 5b1f17b1804b1-4361c3b9d1bmr13850245e9.12.1733908903351; Wed, 11 Dec 2024 01:21:43 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4361e54ef20sm12271745e9.5.2024.12.11.01.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 01:21:42 -0800 (PST) Date: Wed, 11 Dec 2024 12:21:39 +0300 From: Dan Carpenter To: Amir Goldstein Cc: Alexander Viro , Christian Brauner , Jan Kara , Kees Cook , Eric Biederman , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH next] binfmt_elf: Fix potential Oops in load_elf_binary() Message-ID: <5952b626-ef08-4293-8a73-f1496af4e987@stanley.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Stat-Signature: n4jjb6nhuopsuuzegf44z6y4to1w1ka4 X-Rspamd-Queue-Id: BFDF718001B X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733908888-705952 X-HE-Meta: U2FsdGVkX1+RpVgCPWfZDRT49vdsCGGl2GK7y78PSuC6QaWG1e67iuImZf7IjDoQXu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faJnF+epoNfyMVtD6EJVy7nHkViI7ectvZQ6g+Ex8qCe0EPUFoBTnVz24n9KRXl2OdZjIvQVpzVsmPdneK8RPulDQhuEH47Ujd1skV7kUqTa2KW9xpPHewrzcWm3CA/q4Clt4F6CZh4A4y3XcWZVxqVNSMCgYMQHAoa+SGBfgw/KkzhR4DUC0UarS6P5bk1DaOxy5WAGPmBoGSCsVTJTGNUQsHGov2cFwYE5 X-Bogosity: Ham, tests=bogofilter, spamicity=0.315500, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This function call was changed from allow_write_access() which has a NULL check to exe_file_allow_write_access() which doesn't. Check for NULL before calling it. Fixes: 871387b27c20 ("fs: don't block write during exec on pre-content watched files") Signed-off-by: Dan Carpenter --- fs/binfmt_elf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 8054f44d39cf..db9cb4c20125 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1354,9 +1354,10 @@ static int load_elf_binary(struct linux_binprm *bprm) kfree(interp_elf_ex); kfree(interp_elf_phdata); out_free_file: - exe_file_allow_write_access(interpreter); - if (interpreter) + if (interpreter) { + exe_file_allow_write_access(interpreter); fput(interpreter); + } out_free_ph: kfree(elf_phdata); goto out;