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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 25F26C4332F for ; Wed, 9 Feb 2022 12:41:05 +0000 (UTC) Received: from localhost ([::1]:39118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHmHP-0007Zd-Rk for qemu-devel@archiver.kernel.org; Wed, 09 Feb 2022 07:41:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHmAz-0003ob-T5; Wed, 09 Feb 2022 07:34:25 -0500 Received: from kylie.crudebyte.com ([5.189.157.229]:52827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHmAw-0002p6-9P; Wed, 09 Feb 2022 07:34:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Content-Type:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Content-ID:Content-Description; bh=yT6gjUafrH61VY9rJX9omIrT4XSs2aee0EH3trEm0T4=; b=M0cUzKCkRXG+4/GBfacRleVo/r 9LEiRrJJL6p9bNIjnWjwotdSxagb6YNXv8l7/MZu+UFsko+5bRqQZAhwdZasrOkr5iE9FQJHTYxNK eCNfh+hmeBIaeoWPZx+YIwhcp9/fK8ObbgPPCuA4DVgihOVSqax5izpYGa9eDRcttK8Be30Hqnrt9 M2LYRoWNrLu94MAbeOrMqiGcnNO6GheaOgYTNhYltiifLKXFu/dcTvpLA0swvecFUa8Cqv/cWHtb4 5RxaLg6khFshJKV1u/2eAIPA+rivUTZV5UlwUJlgsC8TBbevoj0Hc/roK7BXnqxrDzIE0aVQNR9dr egSeF9CdgOdxVzYhGnFqyVxHH9pzZW7YiLITLACUSxqzYd78XylmgbOkDHOBuEi5nrPDFsARBpEN8 cpm5bxHS6ABhBm0t/7Vn6nAwhNEKb8/SI1F5CVEfJjo1KjyMksU8UHUX8zi+hkLq1x/CDLw+dAwLv 1bnHpB0oLBcfdWTdglxUNY77zCD9J/zSEycSQ/AtGHDkBptdkEtwy1PLtZ5sRPueZCR83DM3D9YIy dbr9l6QUHCnl9aZJ+xj2U2+XU8icttVAYl19/2yeeGcm+sOcM7aaRcOZjCkT+mkHGdmh8q1HJsmDN uWqqv8E3wP6U8iSSXVnSXlNIC83krkLSGyiQsiaf4=; From: Christian Schoenebeck To: qemu-devel@nongnu.org Cc: Vitaly Chikunov , Greg Kurz , qemu-stable@nongnu.org, "Dmitry V . Levin" , Philippe =?ISO-8859-1?Q?Mathieu=2DDaud=E9?= Subject: Re: [PATCH v4] 9pfs: Fix segfault in do_readdir_many caused by struct dirent overread Date: Wed, 09 Feb 2022 13:34:08 +0100 Message-ID: <2508467.LGuOOJKFuP@silver> In-Reply-To: <20220206013419.849161-1-vt@altlinux.org> References: <20220206013419.849161-1-vt@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: pass client-ip=5.189.157.229; envelope-from=qemu_oss@crudebyte.com; helo=kylie.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Sonntag, 6. Februar 2022 02:34:19 CET Vitaly Chikunov wrote: > `struct dirent' returned from readdir(3) could be shorter (or longer) > than `sizeof(struct dirent)', thus memcpy of sizeof length will overread > into unallocated page causing SIGSEGV. Example stack trace: > > #0 0x00005555559ebeed v9fs_co_readdir_many (/usr/bin/qemu-system-x86_64 + > 0x497eed) #1 0x00005555559ec2e9 v9fs_readdir (/usr/bin/qemu-system-x86_64 > + 0x4982e9) #2 0x0000555555eb7983 coroutine_trampoline > (/usr/bin/qemu-system-x86_64 + 0x963983) #3 0x00007ffff73e0be0 n/a (n/a + > 0x0) > > While fixing, provide a helper for any future `struct dirent' cloning. > > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/841 > Cc: qemu-stable@nongnu.org > Co-authored-by: Christian Schoenebeck > Reviewed-by: Dmitry V. Levin > Signed-off-by: Vitaly Chikunov > --- > Tested on x68-64 Linux with btrfs-progs tests and slow qos-test. > Changes since v3: > - Update commentary on qemu_dirent_dup logic. > - Use g_memdup as suggested by Greg Kurz. > > hw/9pfs/codir.c | 3 +-- > include/qemu/osdep.h | 13 +++++++++++++ > util/osdep.c | 21 +++++++++++++++++++++ > 3 files changed, 35 insertions(+), 2 deletions(-) Queued on 9p.next: https://github.com/cschoenebeck/qemu/commits/9p.next Thanks! I plan to send a PR with my current queue to Peter tomorrow. Best regards, Christian Schoenebeck