From patchwork Wed Jun 7 14:42:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13270806 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 EF308C77B7A for ; Wed, 7 Jun 2023 14:42:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CEBC8E0005; Wed, 7 Jun 2023 10:42:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87F378E0001; Wed, 7 Jun 2023 10:42:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F9228E0005; Wed, 7 Jun 2023 10:42:35 -0400 (EDT) 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 5BD288E0001 for ; Wed, 7 Jun 2023 10:42:35 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DDA2F140293 for ; Wed, 7 Jun 2023 14:42:34 +0000 (UTC) X-FDA: 80876217828.25.4413055 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by imf03.hostedemail.com (Postfix) with ESMTP id 1E8AC2001A for ; Wed, 7 Jun 2023 14:42:32 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=bXFeImhQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ansuelsmth@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=ansuelsmth@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686148953; 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=bhU8rJcA/NcmdBFZbG66fI16dsKgmepn+1tYIFC8M3Y=; b=PoyhRlnj8xSHTpzBto9I+uTMKkcKHpVjesgkC8WwW7nxbXE7TGZ7gYFqzD7jpyC7FPhLyq hj+LR9Geq1sr23md7n1SuhgHY8iOSSPTg+YyC4zUPm2NMM3bcWFRFyXbZgitcHOnT+nCPR 9YHwq0CZuIW08A01ybeFplRSLU1DDjs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=bXFeImhQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ansuelsmth@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=ansuelsmth@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686148953; a=rsa-sha256; cv=none; b=JNpifgpXtXs7xPxkhbY3SDryr8V3s6spzf+PXrTKjzfiq03sVN/rbTX/RQDKWv+MRb0w3i kgKloPTMK7BmPpFY/m17G2qRKCLTcpQR18jLa0J4Ut8yKg16qJ47oQt/Rc1AzMKgYrCBK4 06ocGXiypZgz8nioTmXmSV3Olsz7oWo= Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-30ae141785bso7298824f8f.3 for ; Wed, 07 Jun 2023 07:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686148951; x=1688740951; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bhU8rJcA/NcmdBFZbG66fI16dsKgmepn+1tYIFC8M3Y=; b=bXFeImhQdmhi+fiXTrYziTug2rbzZLXJhrXLvGxWuoZ2j7UukUjIt8sAoeX/RF7xv1 UIJtUOm842Gd3oYnQ4uc1hb6B6+MA/hfg9r4H3Hd6U/vNOPgejThO0dav7DufAtYCl6M OXksAOKE/B4XZh3jUtATnWfvmYd1VDBw/RG6ydD8TjwOGxCr0qRJpccgdXxC4PzOkW82 C172foUptIBBIPMcXeHlpmSncRBj4r7KkYtmXktu4geGFPXgytJEs/WoCzv66A8gl82e cAzEr8z+geaUgs3Dh6Jpsl6ZP5g8P1kUAtcjHd9ee+vbQVvkFS3oh0pIi4d0mkaXUPkR tPgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686148951; x=1688740951; 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=bhU8rJcA/NcmdBFZbG66fI16dsKgmepn+1tYIFC8M3Y=; b=VmejuqxTV7FRIWW8SdZg5zGSSsdRSTtSvxqvI5z2jdPDaHhZ8wNpzRJXLQSn+2sVE9 zPfbXJZJIhAiigEfeU9NgdWEcrk0Xr3zmWpm4nqXD6hKmVWa12Db7aBS9EblgbAagSI8 g8PYrlakg5MfZt0Ktp7lcp6K01PAya9uGSkfrxy26q6mTiajpkzY9cLf9jBtvhiG+HlJ J4Vmw89mZji+MNHop5GJCHZItzlgF5d/2NdWxW+V+rwbsKrfjeKhJfEnW/WFzJ9WlLVa 2kcROKF2KgiOObz7/23XrcX4LF3Dhmewsul4zzALsXl9OZ827uw1fdArrL7R2xkZyeDy BPcA== X-Gm-Message-State: AC+VfDzef1krFf+5vVIqaobaZnM2LpXryvBvGgUbBebWYRZwVq6oGxTv F/2Bk+RvSiqLJPpk75g4lFs= X-Google-Smtp-Source: ACHHUZ7FmpM3xOpynYg+M/k9K8xzWpLPv+zJIL90yhFnNkyAYSdt5QSHjwTQLv7gvto2a7w0M12KrQ== X-Received: by 2002:a5d:408f:0:b0:309:4368:a8a0 with SMTP id o15-20020a5d408f000000b003094368a8a0mr4476903wrp.68.1686148950971; Wed, 07 Jun 2023 07:42:30 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id z12-20020a5d4d0c000000b003068f5cca8csm15731342wrt.94.2023.06.07.07.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 07:42:30 -0700 (PDT) From: Christian Marangi To: Alexander Viro , Christian Brauner , Eric Biederman , Kees Cook , Mark Brown , Dave Martin , Catalin Marinas , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Christian Marangi , stable@vger.kernel.org Subject: [PATCH] binfmt_elf: dynamically allocate note.data in parse_elf_properties Date: Wed, 7 Jun 2023 16:42:27 +0200 Message-Id: <20230607144227.8956-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1E8AC2001A X-Stat-Signature: 197n6k4fdsmz4w3uy75k1f3mtet5447t X-HE-Tag: 1686148952-859457 X-HE-Meta: U2FsdGVkX19v3AD55vq5w2Vn9sKW1d57qJkUjIaoSqMmXWKex3vaWTzY2GNKL99Qb4qoZYkfz9x3UAn3fnYPBU8K/z+ljoIxJz6nK89lrtO0mzmzzT7/OkIC7XTVwGHx6GIjCOgBmm7kwJAnRUwsotBq1u+BjxZGhxr2x5ml856STfAr8c/6fj0j/sncKU+NcJ+NheSg0SxnDwUGhrtwHbRLbyYAvzqsUH84QPJtRDVQKdFF4FPOoI7RWQC3fFHzOupLq+e1b3tSMxXioehfULoH5PPzRJxV6dVtTia65cfbfOYQ/JQ53SfXMT2YDU2dfGhB7kmqPyK1rxMup8WA+bOIIhEy1foI3cC3h1g5ML/vIKj4gOvvGHxCz660wW/WfHJ/LlcEEWtWVNYuY8DYffD6SrWtzsST79PYB68O/EpdOZ6lw6Q2zZBovD1rAs1wl3cURtOSAH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5U88= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Dynamically allocate note.data in parse_elf_properties to fix compilation warning on some arch. On some arch note.data exceed the stack limit for a single function and this cause the following compilation warning: fs/binfmt_elf.c: In function 'parse_elf_properties.isra': fs/binfmt_elf.c:821:1: error: the frame size of 1040 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] 821 | } | ^ cc1: all warnings being treated as errors Fix this by dynamically allocating the array. Update the sizeof of the union to the biggest element allocated. Fixes: 00e19ceec80b ("ELF: Add ELF program property parsing support") Signed-off-by: Christian Marangi Cc: stable@vger.kernel.org # v5.8+ --- fs/binfmt_elf.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 44b4c42ab8e8..90daa623ca13 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -768,7 +768,7 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr, { union { struct elf_note nhdr; - char data[NOTE_DATA_SZ]; + char *data; } note; loff_t pos; ssize_t n; @@ -785,29 +785,41 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr, return -ENOEXEC; /* If the properties are crazy large, that's too bad (for now): */ - if (phdr->p_filesz > sizeof(note)) + if (phdr->p_filesz > sizeof(*note.data) * NOTE_DATA_SZ) return -ENOEXEC; + note.data = kcalloc(NOTE_DATA_SZ, sizeof(*note.data), GFP_KERNEL); + if (!note.data) + return -ENOMEM; + pos = phdr->p_offset; n = kernel_read(f, ¬e, phdr->p_filesz, &pos); - BUILD_BUG_ON(sizeof(note) < sizeof(note.nhdr) + NOTE_NAME_SZ); - if (n < 0 || n < sizeof(note.nhdr) + NOTE_NAME_SZ) - return -EIO; + BUILD_BUG_ON(sizeof(*note.data) * NOTE_DATA_SZ < sizeof(note.nhdr) + NOTE_NAME_SZ); + if (n < 0 || n < sizeof(note.nhdr) + NOTE_NAME_SZ) { + ret = -EIO; + goto exit; + } if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 || note.nhdr.n_namesz != NOTE_NAME_SZ || strncmp(note.data + sizeof(note.nhdr), - GNU_PROPERTY_TYPE_0_NAME, n - sizeof(note.nhdr))) - return -ENOEXEC; + GNU_PROPERTY_TYPE_0_NAME, n - sizeof(note.nhdr))) { + ret = -ENOEXEC; + goto exit; + } off = round_up(sizeof(note.nhdr) + NOTE_NAME_SZ, ELF_GNU_PROPERTY_ALIGN); - if (off > n) - return -ENOEXEC; + if (off > n) { + ret = -ENOEXEC; + goto exit; + } - if (note.nhdr.n_descsz > n - off) - return -ENOEXEC; + if (note.nhdr.n_descsz > n - off) { + ret = -ENOEXEC; + goto exit; + } datasz = off + note.nhdr.n_descsz; have_prev_type = false; @@ -817,6 +829,8 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr, have_prev_type = true; } while (!ret); +exit: + kfree(note.data); return ret == -ENOENT ? 0 : ret; }