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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6597C54E58 for ; Tue, 26 Mar 2024 05:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tsJ13nVv1qlfZL78OR18BWPi9ZVteTAZmiqsf+fFuHU=; b=W7eXyz94pg9HfR m/L83nfacu/JpRFD7Pnbr4dE/xs/fHabraMtfvo1E5SJ7Rp8kUqTvvUXnSbtYh4AOrdftCw9vjPfs SHkuxlu/fSB7AN03eEs9Yf0ytpgQBUMtg2p/mvGgS3fojACkh0qlQlQ6oXSuUhwlqgIG/K/dIQoHp vnOuPqeD+OuawSQ+ha0dFkk4BsWqswblryjRGyxiTXaNldZqSU7eym8DkTXwgHQsy98jNNTJu5ebJ k0jYbkoVAs8IbU1UkbTYrwMxi2HrMod6ps15zE6RmGpsIxV6gnRFMTz0gvuGMQbo8I04jCdY4/G5G cQOQmYIxlC//qvcOBfYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rozl1-00000003BVK-3oOH; Tue, 26 Mar 2024 05:53:59 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rozky-00000003BUp-3YLH for linux-riscv@lists.infradead.org; Tue, 26 Mar 2024 05:53:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2307ACE1C97; Tue, 26 Mar 2024 05:53:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C428C433C7; Tue, 26 Mar 2024 05:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711432432; bh=p1h/3bDBMeEKRt9AkpnulPRNIkXpjpAoN4qqivDNeo4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ELTGzE3PynLd7uPVfz8E5W0K3gyQzaLC48bKjSGt4LH6a1TaQ32gglVChyRIr9cZV MGIBs/QmaL/2l6RWW6Ma+QaRex3qjpZfWpmOKLgQnUFod30tlNQizPVB563XxzArDd iSMuny8WI2Kp6ajUZl56OnraUYxIfPJ3DvEpUw0pYXx/KNh4p+G0ZlSxd9qCYVTiEN O34oOfWdPvqyGxOCw5j0tBBFFN7kJn5eU48vzRFIFVd+g3PTph5a676jx9dIFMWJRY jMnv/Wmk8ZWQvQflZ301Na7ELVcQXXvqTw5S9LtdUhF5tBJ8kG+wxQ8kYx+rBK1Afh yef08gMFu2/yQ== Message-ID: <4acb96b2-949d-4f08-99c6-08bb30ead928@kernel.org> Date: Tue, 26 Mar 2024 14:53:49 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] binfmt_flat: Fix corruption when not offsetting data start Content-Language: en-US To: Stefan O'Rear , linux-mm@kvack.org, linux-riscv@lists.infradead.org Cc: Eric Biederman , Kees Cook , Damien Le Moal , Greg Ungerer , Waldemar Brodkorb References: <20240326032037.2478816-1-sorear@fastmail.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20240326032037.2478816-1-sorear@fastmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240325_225357_133694_F68D3C25 X-CRM114-Status: GOOD ( 18.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On 3/26/24 12:20, Stefan O'Rear wrote: > Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") > introduced a RISC-V specific variant of the FLAT format which does not > allocate any space for the (obsolescent) array of shared library > pointers. However, it did not disable the code which initializes the > array, resulting in the corruption of sizeof(long) bytes before the DATA > segment, generally the end of the TEXT segment. > > Use CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard initialization the s/initialization the/the initialization of the > shared library pointer region so that it will only be initialized if > space is reserved for it. > > Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") > Signed-off-by: Stefan O'Rear > Tested-by: Waldemar Brodkorb It feels like CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET is not a very good name... Maybe something like CONFIG_BINFMT_FLAT_NO_SHARED_LIBRARY would be better. But renaming can be done in a followup patch. Reviewed-by: Damien Le Moal --- > fs/binfmt_flat.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c > index c26545d71d39..70c2b68988f4 100644 > --- a/fs/binfmt_flat.c > +++ b/fs/binfmt_flat.c > @@ -879,6 +879,7 @@ static int load_flat_binary(struct linux_binprm *bprm) > if (res < 0) > return res; > > +#ifndef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET > /* Update data segment pointers for all libraries */ > for (i = 0; i < MAX_SHARED_LIBS; i++) { > if (!libinfo.lib_list[i].loaded) > @@ -893,6 +894,7 @@ static int load_flat_binary(struct linux_binprm *bprm) > return -EFAULT; > } > } > +#endif > > set_binfmt(&flat_format); > -- Damien Le Moal Western Digital Research _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DFA1C54E58 for ; Tue, 26 Mar 2024 05:54:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95C256B0083; Tue, 26 Mar 2024 01:53:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 90C7C6B0085; Tue, 26 Mar 2024 01:53:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D3C16B0087; Tue, 26 Mar 2024 01:53:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6DBEE6B0083 for ; Tue, 26 Mar 2024 01:53:59 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 471BC16097F for ; Tue, 26 Mar 2024 05:53:59 +0000 (UTC) X-FDA: 81938124198.02.D18A6F6 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf17.hostedemail.com (Postfix) with ESMTP id 2A0B040004 for ; Tue, 26 Mar 2024 05:53:56 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ELTGzE3P; spf=pass (imf17.hostedemail.com: domain of dlemoal@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=dlemoal@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711432437; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5QlfUVufuK4U5dGUPfioiLT/VHfX/dTyJ+35DRAfybU=; b=pxRTg5+pZIsYVQRU4TrOW3yxsjb+wjBelRKg27t2icQMN5a91wtCXEvmfYLP01O1EfYpor r1tInihr/SDwjQPb1I6vcK0LVhQyu1f5JL9CPOioNW1/OAMQ1SiW14EpgheaftHiWZ9tfY EAbdaOEvpRjDGw9ctJox2fidM4sgavU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711432437; a=rsa-sha256; cv=none; b=CGRB6JWzAwaKX0tvp1JowRfN0nWU1yLAIyK9VLcxKl3JidV8oEbt0W65ZoRVMUhWtd99Gm aMqnUvF4XCxKJClt0/QbcAG/rh8WjdV/dHrMpVuMaNk/AVnBifl0Z8FaGh4sH4NqJsAgkk 51/Tq9aQO8oe/lPK8QsJMk7zQlh3USM= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ELTGzE3P; spf=pass (imf17.hostedemail.com: domain of dlemoal@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=dlemoal@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 2307ACE1C97; Tue, 26 Mar 2024 05:53:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C428C433C7; Tue, 26 Mar 2024 05:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711432432; bh=p1h/3bDBMeEKRt9AkpnulPRNIkXpjpAoN4qqivDNeo4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ELTGzE3PynLd7uPVfz8E5W0K3gyQzaLC48bKjSGt4LH6a1TaQ32gglVChyRIr9cZV MGIBs/QmaL/2l6RWW6Ma+QaRex3qjpZfWpmOKLgQnUFod30tlNQizPVB563XxzArDd iSMuny8WI2Kp6ajUZl56OnraUYxIfPJ3DvEpUw0pYXx/KNh4p+G0ZlSxd9qCYVTiEN O34oOfWdPvqyGxOCw5j0tBBFFN7kJn5eU48vzRFIFVd+g3PTph5a676jx9dIFMWJRY jMnv/Wmk8ZWQvQflZ301Na7ELVcQXXvqTw5S9LtdUhF5tBJ8kG+wxQ8kYx+rBK1Afh yef08gMFu2/yQ== Message-ID: <4acb96b2-949d-4f08-99c6-08bb30ead928@kernel.org> Date: Tue, 26 Mar 2024 14:53:49 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] binfmt_flat: Fix corruption when not offsetting data start Content-Language: en-US To: Stefan O'Rear , linux-mm@kvack.org, linux-riscv@lists.infradead.org Cc: Eric Biederman , Kees Cook , Damien Le Moal , Greg Ungerer , Waldemar Brodkorb References: <20240326032037.2478816-1-sorear@fastmail.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20240326032037.2478816-1-sorear@fastmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 2A0B040004 X-Rspam-User: X-Stat-Signature: xn7eokg6qkgfhwz3hpy95e78csc5gm37 X-Rspamd-Server: rspam03 X-HE-Tag: 1711432436-574541 X-HE-Meta: U2FsdGVkX1/8yYe8w38l/frSvP2yRTL/cNfIT4LcI17h9GKve7YgPrU86m5iaJHMkqPXjsmYvJd20yWilU/YDnhV2f2ThKojPbhU7GH/QKVMJurD0WgM1bQobT55DQrZqKPq91xS12qN+FPkfShBTdJZ/Cbi++aP1oVRt6bG+Ubkt5OoYGyJNYohJDaHC1Hw86R4wFqE+qWtIZqClbzpHZaRMck1sV6gR4fEjJAPgZfWj/O4LTFEC7NhAoqvl2UT+roS7RIyZCZgwDINhJ+fCaqlrObSOHbAbORJZPn47H4Z1k4ihPhClTLmJN7IOcinIBb/X+4BaLRP1sKTywAPgtmLyc6fBags0x5l9fgmqMFEYyfAXB0QsiGlAdXLVDvBXtj9Snjd9ptCnqciSNGJm224nGf3I9F35xffmunlOqdE9t3znzy01mfiLtvSbk9tAWnUrWP2RsmToHP8N+UKRgeEPSi5Y7yYV7IpRq3tyitusO06pAVHYd5eM2prhpE/yPG7dEJXwvWAFuictMuR07VDGS/kTyeI3netGmeBETS6oa8JqJPX/jopQ5ndckdvfSBwHcAyb+xe7OyxDxskF2kgjIjylpxJC6u019JHd+YTKDMHs3O9punBqhYBIUpJA7Vto8aVl4skBfRug6eJzlLcSln0T9NGL3AUaV39SsSc0/VK8QzVddYJgUJLcGM9NitXfTazMoqaj0WycCdMBI47uhEkKpHvpFrZ0q7GWBp3KIjLZlnNtCgQjiEMZUGtLrA7WRl5CJYMiveGl+NwINgphg14ngTOATmDo9fCiCkVqBHQr7Dowj784A+AXJ1OyOOSqkPI22gY8c7LEHXIYZz4XAuf1iMBA46Oaw3qvWsrQY7s1A9J2atKllnyy285bEtAPnMiua1qir+zfkvQ69GyFRv+1U0QQz4F0SeOldE9Kfmbm0m+86UJWX5Mfj6ge7ruTT7xAZ49xD0rMhq rOErNg/a cB3mInpVu+WmbD0XIJHM30M7MZH37DUX30dHB 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: List-Subscribe: List-Unsubscribe: On 3/26/24 12:20, Stefan O'Rear wrote: > Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") > introduced a RISC-V specific variant of the FLAT format which does not > allocate any space for the (obsolescent) array of shared library > pointers. However, it did not disable the code which initializes the > array, resulting in the corruption of sizeof(long) bytes before the DATA > segment, generally the end of the TEXT segment. > > Use CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard initialization the s/initialization the/the initialization of the > shared library pointer region so that it will only be initialized if > space is reserved for it. > > Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start") > Signed-off-by: Stefan O'Rear > Tested-by: Waldemar Brodkorb It feels like CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET is not a very good name... Maybe something like CONFIG_BINFMT_FLAT_NO_SHARED_LIBRARY would be better. But renaming can be done in a followup patch. Reviewed-by: Damien Le Moal --- > fs/binfmt_flat.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c > index c26545d71d39..70c2b68988f4 100644 > --- a/fs/binfmt_flat.c > +++ b/fs/binfmt_flat.c > @@ -879,6 +879,7 @@ static int load_flat_binary(struct linux_binprm *bprm) > if (res < 0) > return res; > > +#ifndef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET > /* Update data segment pointers for all libraries */ > for (i = 0; i < MAX_SHARED_LIBS; i++) { > if (!libinfo.lib_list[i].loaded) > @@ -893,6 +894,7 @@ static int load_flat_binary(struct linux_binprm *bprm) > return -EFAULT; > } > } > +#endif > > set_binfmt(&flat_format); > -- Damien Le Moal Western Digital Research