From patchwork Thu Jan 18 15:06:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 13522939 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 3DF86C47DB3 for ; Thu, 18 Jan 2024 15:07:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C90A96B0093; Thu, 18 Jan 2024 10:07:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C41336B009A; Thu, 18 Jan 2024 10:07:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B09746B009B; Thu, 18 Jan 2024 10:07:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A12D46B0093 for ; Thu, 18 Jan 2024 10:07:03 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5CBD81603E7 for ; Thu, 18 Jan 2024 15:07:03 +0000 (UTC) X-FDA: 81692759526.17.C0B5217 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf12.hostedemail.com (Postfix) with ESMTP id 7F0D440005 for ; Thu, 18 Jan 2024 15:07:01 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Hu5OKKpS; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of jcmvbkbc@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=jcmvbkbc@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705590421; a=rsa-sha256; cv=none; b=kxS9MpfFEKWqJW95yeMFoJda/iL/RwQwzEQOvlLgISXtZwpsPI9thUe2DjdvuiKSQyH3wI 2v7yEHxAB2Loa4zSPbp3uqlTUqZTTU98ZD0c9hJd5ZAZZ884rDQF8b2bG8dA0OwEQv5Uis 9tLwkoqKiOVc50B+/j5GVhaShyROqRQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Hu5OKKpS; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of jcmvbkbc@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=jcmvbkbc@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705590421; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=VgRCRgtT2LBOn4OGPEhJQpmUEWiVNpEx0m8L9kHq3Kg=; b=2h8iYPdcWpe1B0Mg7szEyxmp80ThcJO6e4aXGg/mcii50y6+0og6orC8LdUCKvKf6TT+wx i7DJGncrSgC1QNdeNQ3avTM5MI/hMitmmORBvlHRt4Q8xr6NdEL9ckgsS3hDlkt2jwx45r J8tBxjXYYrk5Hv4KNvMioD7nL8vemv0= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6dbb26ec1deso277200b3a.0 for ; Thu, 18 Jan 2024 07:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705590420; x=1706195220; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VgRCRgtT2LBOn4OGPEhJQpmUEWiVNpEx0m8L9kHq3Kg=; b=Hu5OKKpS1RwljEi1//ee61MAtoH+nKIMxpQHyyUUKWrA74n0dplMYpsKd/avcQ4ruI OQfyZihmYcZA4Y8oMYf8TMePoOVUjAgFCd/3qNceNYQfBdhl897xm4EapPTkrVeqj101 7E9AI7Udllc8NJ5lJXgwAQ/xLrLD25FI19+ou6zW7ZM5IuLXMU3CzvHDfD6sBOuhIdPE V88HemunidHbaazPi3i3SYc5DPl8SEGCEL5wUW8Rj52h/IunHYRKIBF2xMYZFG1mIau7 Q7R5nfS8Sp0AoTEAEQubsTtVS0AwSoTRMoCZlcdkAzhkQQXT4ebx3Zj/5FEHU+uaRQc1 ujxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705590420; x=1706195220; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VgRCRgtT2LBOn4OGPEhJQpmUEWiVNpEx0m8L9kHq3Kg=; b=wWh/bUYcJSmlSEy1KytTbi4zBGiFw8XX6wLLn2FgVqDQtivaxyJ5oYkzksFPkbLOzh Zyiaaxp7f1CmXTSul4siUbCP++Y8pX20m6j86xozDsgqRiGlahU04Yp8YmOzDQ7rfvmE 6TrWrmOsSVEOLIqhP8XvS2SNsjFiAj4pAmPDIQnUYk7AammGi7yULwQkUhzo7HMH9yhI uMU7W2erWOMj0mSkSMKiyIGvsApjKvGfSQia+q12oNntpAsGPXs5qp5clJrX2+6yjl+1 7bCg7hN7nPqfIUuFJ2NAMT3OYkI+ReGC/QWH/+NAs8Ksi743Se3R+LvG4PlGagLoq7l7 FxUw== X-Gm-Message-State: AOJu0YzJLzKutXPS2/gxy7ijGaB5a4hwUfi2VShLMWWLVmaFd4GpooRV KiyyqZTO/nqpiKmffr5Ca9Q+zxf63JThGN6ObGqEvxeqf4ONsjel X-Google-Smtp-Source: AGHT+IEfZE0AN8dYVVy87hfIcMTIj3hFPqed1PcWPc5hh6Us7z9PBuDl2J1gfCUl94i+14NK3MXaoQ== X-Received: by 2002:a05:6a00:240a:b0:6db:829c:12bf with SMTP id z10-20020a056a00240a00b006db829c12bfmr1328321pfh.28.1705590420346; Thu, 18 Jan 2024 07:07:00 -0800 (PST) Received: from octofox.hsd1.ca.comcast.net (c-73-63-239-93.hsd1.ca.comcast.net. [73.63.239.93]) by smtp.gmail.com with ESMTPSA id p10-20020a63f44a000000b005c19c586cb7sm1668892pgk.33.2024.01.18.07.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 07:07:00 -0800 (PST) From: Max Filippov To: linux-kernel@vger.kernel.org Cc: Chris Zankel , Alexander Viro , Christian Brauner , Eric Biederman , Kees Cook , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Greg Ungerer , Geert Uytterhoeven , Max Filippov Subject: [PATCH] fs: binfmt_elf_efpic: don't use missing interpreter's properties Date: Thu, 18 Jan 2024 07:06:37 -0800 Message-Id: <20240118150637.660461-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7F0D440005 X-Stat-Signature: hjzzzaodzgsgbsgucnb6we9m9wrjrqer X-HE-Tag: 1705590421-911969 X-HE-Meta: U2FsdGVkX1+8sgG3uU4xGexp4n53VvuPC+Q1RaYlEb6DtG2FLM7S0FvImRy13SxM+pwql1db50OcPtu2qp9k2fytemOdw9JusWHY7cc6UqzuePmlP/GY3+vLw8aov61ZPmilcnOgzcWNrteFxzGILcS9bLd2BUzw1UKbS51QgQDWNJ7LizlZfIChjyqtdN2RGW2U0DpmdEa2/4FwZ58u5CwSy62ZhJxxXGdwVoqPwJglP+fbrZX/dlS4tzCuHMmq9gH8KKDWSrS0uw219p+NH+6Z9BZWW4PLCL4sAVSJ7te3s5LV8LodldVzRE/kH/YuQUiHi36fkrJtZ9dMuKFS4kxkjxs85uZPJCHxTxcgJucxVLbWyXYGHd91IeptaAWoOxJk+GSPmVhB/y0WG3D0vRx9In45X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= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Static FDPIC executable may get an executable stack even when it has non-executable GNU_STACK segment. This happens when STACK segment has rw permissions, but does not specify stack size. In that case FDPIC loader uses permissions of the interpreter's stack, and for static executables with no interpreter it results in choosing the arch-default permissions for the stack. Fix that by using the interpreter's properties only when the interpreter is actually used. Signed-off-by: Max Filippov --- fs/binfmt_elf_fdpic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index be4e7ac3efbc..f6d72fe3998c 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -322,7 +322,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) else executable_stack = EXSTACK_DEFAULT; - if (stack_size == 0) { + if (stack_size == 0 && interp_params.flags & ELF_FDPIC_FLAG_PRESENT) { stack_size = interp_params.stack_size; if (interp_params.flags & ELF_FDPIC_FLAG_EXEC_STACK) executable_stack = EXSTACK_ENABLE_X;