Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8365274rwp; Wed, 19 Jul 2023 08:50:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlFOe11+t/WvlMq4X9X1D5w8RG8Xi2132mg1JN7U2luHjpbY/5oc1y1YDSB3wtx/LUvyD7MD X-Received: by 2002:a17:906:854b:b0:988:6491:98e1 with SMTP id h11-20020a170906854b00b00988649198e1mr2424145ejy.42.1689781815461; Wed, 19 Jul 2023 08:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689781815; cv=none; d=google.com; s=arc-20160816; b=n8X2cfIFX+e2LZdl8p+B6nf8+6jXVkRIfrJsOesYUcfDV2NdagOii35tFkCierX2Qo +lSASnWmJCTjlyZw2r3q3PxVpcw8f1vXPb5Yextkwc0cgTAK1fAGsQwkT9VSQz0qROsM 3db5q3twYhGt5Ro+vS8jwEJ4tVvzL/ImDN9jF7LCVuBt880Bi9do/X2PcZ/0bzi+UItY aSLFMr+CGOrhMpc9aAQOwgfmIeopG2h5jBGfTUqCaXSQ3IPdSqQJ2jWzMDCMuxqMuU8J 7qmcWQmM0lTjjfp/AGRBawWYcRAswKDWf3VwEtlNVkgmuO8nfzqNBMfJ9aI6j8DJfoep e5vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=76niNhHGhP25frfuWEqV5QNEgyLBCNjhHXOoO/mvUpA=; fh=5Wm0Lj6Dmw4Cqb5CoMj2+Qdmyu5vdp+Aveq6osouA2o=; b=fA9EfBWup496HyvkKbsMZyQQAuw6WgE26lyAAyNpkgyMaun0WCImGeVY+NFSC6dHz4 7YjgMGREf16p3C0zVCZonMIW/HR7/P6wHghcoa93oanoRfP2tv/bJv+Lj7mh3tbtJB8S rEj3VJNLeu2C+z2SQISy5zO5iVQlYLHE59kLms5OlkQF0tLyMMmAny9owCAWpVjNG2HU NZMuTK8C/5K4wjTHgIrG9jVgD1YL+32St/JQC1Vf5DMicZ6pCf5KdqulhPYnyifZuniT V1h+b3BwwkyISZWEXjeTl42mWPJKwMyQxjn1sa0mjDh2GSYAcPimbq7MaRrGT34sMXLV V0Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=C2tE11QN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a1709063aca00b00991f5659833si3007784ejd.152.2023.07.19.08.49.50; Wed, 19 Jul 2023 08:50:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=C2tE11QN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbjGSPbR (ORCPT + 99 others); Wed, 19 Jul 2023 11:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231824AbjGSPbP (ORCPT ); Wed, 19 Jul 2023 11:31:15 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2577BE69 for ; Wed, 19 Jul 2023 08:31:11 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bb2468257fso25597335ad.0 for ; Wed, 19 Jul 2023 08:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689780670; x=1690385470; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=76niNhHGhP25frfuWEqV5QNEgyLBCNjhHXOoO/mvUpA=; b=C2tE11QNyHEdr8f5HlDoKFZ9tYJiWeCUkV8xRIniZ9FmpGbVVIRIzXRdTPPJhhyT3L hkB1C1kqZ/BowWDR4FAH9ugKoHk2U78rjNGfy/Dc1jLIEj6kn90ktG/3KepI8Ji3fbih G2etcPHNxryDzGo7JhXv5mB7Ej18QL/3AhNd8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689780670; x=1690385470; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=76niNhHGhP25frfuWEqV5QNEgyLBCNjhHXOoO/mvUpA=; b=O1AIBWb9kEwND7cIYxV/dK1aOlEyjPJr93gdJFhzUII5OQznrVyl9/x7voxrW1VNj/ h1MPqeGXXKiOohqFSqB/ddRhFYEh9CtfLKcg3MKhaX06uEVXPPI46Dnl+KIIAm+Scp/5 iIfab/4MDE3FqU4PLHzcdk/zX1EX6P5zpiKUmklhNrBo+LsCxoteYB7EfgrIY6nWAYFn kUFgMzzutYT5LqkJdZEDMjbXtMVrRyJhGE6jtpgX3PlkNgIW9rEck1w09Mdh/hxoq9ZA Etk/nI3lvq/VfjHr0iXuZmofTrwIH8ojb8x7Vt6yDQEe4mGC/tPDkJTojNZ2+q1P1/xh lFRw== X-Gm-Message-State: ABy/qLYAyBVwEr7EAmkmq+Dz9QdnjExHhUOwds4vPNMiqgAkk7sOWE/K NDbqyb5TrfOiF5rlgLrOOSF3eQ== X-Received: by 2002:a17:90a:9307:b0:263:f7ce:335e with SMTP id p7-20020a17090a930700b00263f7ce335emr15559754pjo.43.1689780670377; Wed, 19 Jul 2023 08:31:10 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id c1-20020a170902d48100b001b896d0eb3dsm4151122plg.8.2023.07.19.08.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 08:31:09 -0700 (PDT) Date: Wed, 19 Jul 2023 08:31:08 -0700 From: Kees Cook To: Larry Finger Cc: Hans de Goede , Azeem Shaikh , LKML , linux-hardening@vger.kernel.org, "Gustavo A. R. Silva" Subject: Re: Crash in VirtualBox virtual machines running kernel 6.5 Message-ID: <202307190823.086EFD42D9@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 19, 2023 at 10:02:36AM -0500, Larry Finger wrote: > Hi, > > When I try to start a VirtualBox virtual machine running kernel 6.5-rc2, it > gets a kernel bug as follows while trying to mount a vboxsf-shared mount: > > Jul 19 08:48:19 localhost kernel: detected buffer overflow in strscpy > Jul 19 08:48:19 localhost kernel: ------------[ cut here ]------------ > Jul 19 08:48:19 localhost kernel: kernel BUG at lib/string_helpers.c:1031! > [...] > Jul 19 08:48:19 localhost kernel: Call Trace: > [...] > Jul 19 08:48:19 localhost kernel: vboxsf_fill_super+0x3bc/0x3c0 [vboxsf 447dff7257fbc53f0b47ed873d2b02eb4773401c] > [...] > > The traceback points to the strscpy() added in commit 883f8fe87686d, which > ironically was submitted to avoid buffer overflows using strlcpy(); however, > I do not think that is the problem. My suspicion is that it comes from > struct shfl_string, and the definition of the variable-length arrays in the > union, and that their lengths are confusing the kernel's string handling > routines. Ah, hm, I think this may still warn with 883f8fe87686d reverted, as it seems the issue is the fake flexible arrays in struct shfl_string. Likely the patch manifesting the false positive is df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3"), if you're building with GCC 13. > I will be happy to test any proposed patches. Thank! Can you see if this fixes it? diff --git a/fs/vboxsf/shfl_hostintf.h b/fs/vboxsf/shfl_hostintf.h index aca829062c12..243d1b91bb45 100644 --- a/fs/vboxsf/shfl_hostintf.h +++ b/fs/vboxsf/shfl_hostintf.h @@ -68,9 +68,8 @@ struct shfl_string { /** UTF-8 or UTF-16 string. Nul terminated. */ union { - u8 utf8[2]; - u16 utf16[1]; - u16 ucs2[1]; /* misnomer, use utf16. */ + DECLARE_FLEX_ARRAY(u8, utf8); + DECLARE_FLEX_ARRAY(u16, utf16); } string; }; VMMDEV_ASSERT_SIZE(shfl_string, 6); (I note that "ucs" is used in the kernel source, and contains a comment that it shouldn't be used, so I removed it.) -- Kees Cook