Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2547046rwo; Sun, 23 Jul 2023 18:37:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlEBclWn/olHxGkvo91aSh80aLkvG3+L/DZkcAHJnmakVaClRCFBr4rk4SErrx+Bir7UmcbI X-Received: by 2002:a17:906:64cf:b0:992:a9c3:244f with SMTP id p15-20020a17090664cf00b00992a9c3244fmr9803356ejn.4.1690162660653; Sun, 23 Jul 2023 18:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690162660; cv=none; d=google.com; s=arc-20160816; b=CGU7EwA9YsmsVg6LobBDHs0d2ARw9bBfzKxFa5dNugzGeVWwcx5Vw6Z8Bqk6PEWOkk Fcteq2WEhw1giYpx5cfaDCZG5FUq7D2hREebPMzoeCE6knfPhc/MJ0XsctQrzR5UHsvZ 5NaC2vtgPx/45kwGUkNRHatz4skqNlSKtqC5c6oQPn4CaAW1mrcAYKWwYXBw7F75j71y zIEPYI8wtLG8kbOodnaGXFDDH6Jt+USs6E2dtZmLOtjSA7vxF/0a2BtrMB00Ia07VNhn z3iIdSHN8di6yCfbL9d/In9CPZUJSTFnb//Znmu8fNmCgCpffVfWUYocJ7A/b4DapY1Y W97Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aoHsrnysAdgrsQijhN8DUQUWhGhGeROn5KsD+ES8gk8=; fh=bnaFLYwELmUFzo23v1AwpRX/ciyps03VSxJdH+47UYg=; b=yhvBhjIR4XtTZnmaBYKfJw/Y0sP+gDGQ/cLHmETbnndV/ir3ZSY37Dk88bX5dKXc3B Qgxv0NHqG5yyRsLUbjlBgSO4qagnjPZIZl6V5jjf2cO95e8qW56MSB2CqnXGyoq9gNBK ssMypA6QwW2BMP1Lfs3O8cy9KCv6Ns6u7+66JuWlRRpm5FOr+SrbBxHVOcEyynIOJS+4 I7e9m/EGJ8giGSVuSCQzpbDg2AQcZVIXD8OvIV8QAobULKJ3xJXS+7esAAS2zKoB2kr2 Gzc0dcn5T5akbklWIlgDIfP3M9mYnykzGXsAZmGCzOWEDMG/SGldLwvgdgWB4Wt4X4Sb 9ibw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i9YN0AAk; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a170906250d00b0099396527229si5209136ejb.65.2023.07.23.18.37.16; Sun, 23 Jul 2023 18:37:40 -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=@kernel.org header.s=k20201202 header.b=i9YN0AAk; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbjGXBXs (ORCPT + 99 others); Sun, 23 Jul 2023 21:23:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230474AbjGXBWw (ORCPT ); Sun, 23 Jul 2023 21:22:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DC51737; Sun, 23 Jul 2023 18:22:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4431A60F1D; Mon, 24 Jul 2023 01:20:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9B19C433C7; Mon, 24 Jul 2023 01:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690161648; bh=p62JdF+2MEhQfOERPRBStL6d3PjNgVIJpUiixC9DnRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i9YN0AAkY4FUtum8GSwkZeCG9qJsegh/RsU3X5eM3UX1zMpmdEPkEcIiog0Ud43yx TKxzk/bXGEUY3FRU1ifi33Sp9bI8Z67WXhI+UQV1z0TKKUPXQNsmiGC0DRzHKt/fFo 1TFQaSand8oSJ87oXNSTJj4UP0HKKryAYn3k7VKEKbsyovDi03gpIJgQ6oO53WEhOd zxLHt8uncOICKbyGjwsbElDYBIWOVTpQbV1X4cbYNCaY+Gm1ecRetgrg1+ZyqDhMgm ZVsFE1Y51F5W55jqBQpyUpxIsl9M503zuoHrLj5s48Ptgs+xHTY28n9iuYAJA31z0/ 4r5OER2eatnYw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christian Brauner , Amir Goldstein , Sasha Levin , miklos@szeredi.hu, linux-unionfs@vger.kernel.org Subject: [PATCH AUTOSEL 6.4 51/58] ovl: check type and offset of struct vfsmount in ovl_entry Date: Sun, 23 Jul 2023 21:13:19 -0400 Message-Id: <20230724011338.2298062-51-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724011338.2298062-1-sashal@kernel.org> References: <20230724011338.2298062-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.4.5 Content-Transfer-Encoding: 8bit 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Christian Brauner [ Upstream commit f723edb8a532cd26e1ff0a2b271d73762d48f762 ] Porting overlayfs to the new amount api I started experiencing random crashes that couldn't be explained easily. So after much debugging and reasoning it became clear that struct ovl_entry requires the point to struct vfsmount to be the first member and of type struct vfsmount. During the port I added a new member at the beginning of struct ovl_entry which broke all over the place in the form of random crashes and cache corruptions. While there's a comment in ovl_free_fs() to the effect of "Hack! Reuse ofs->layers as a vfsmount array before freeing it" there's no such comment on struct ovl_entry which makes this easy to trip over. Add a comment and two static asserts for both the offset and the type of pointer in struct ovl_entry. Signed-off-by: Christian Brauner Signed-off-by: Amir Goldstein Signed-off-by: Sasha Levin --- fs/overlayfs/ovl_entry.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h index fd11fe6d6d45f..6b9f7917fc1bb 100644 --- a/fs/overlayfs/ovl_entry.h +++ b/fs/overlayfs/ovl_entry.h @@ -32,6 +32,7 @@ struct ovl_sb { }; struct ovl_layer { + /* ovl_free_fs() relies on @mnt being the first member! */ struct vfsmount *mnt; /* Trap in ovl inode cache */ struct inode *trap; @@ -42,6 +43,14 @@ struct ovl_layer { int fsid; }; +/* + * ovl_free_fs() relies on @mnt being the first member when unmounting + * the private mounts created for each layer. Let's check both the + * offset and type. + */ +static_assert(offsetof(struct ovl_layer, mnt) == 0); +static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *)); + struct ovl_path { const struct ovl_layer *layer; struct dentry *dentry; -- 2.39.2