From patchwork Sun May 21 08:28:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 96833 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp773027vqo; Sun, 21 May 2023 01:52:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mQiWlqcrt2ATlP0fxs3vo9uXC2uAFZKKmKvvQd1haSSk902K4rDhSQeMO4Uy9VzL6RMew X-Received: by 2002:a05:6a20:a127:b0:101:b080:e763 with SMTP id q39-20020a056a20a12700b00101b080e763mr8156454pzk.31.1684659169486; Sun, 21 May 2023 01:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684659169; cv=none; d=google.com; s=arc-20160816; b=awqzvmioOt+y/czhv1FV1zoPJx32IAYcVWbegG1mbtkHli22dYNS6N6VT4wHNExVGA kcl0AO18jch32tl8aK/BXLj8Qmcm9wu4cPB1guGceb2/A2V9T3XDOHLj2ERaKjtuSG3P +WfvWTFP4U/IXbtoU0yynQXqSojEb2H6JyHAO8IXK3rUrHmyVSBgo/Du6yy4+FUw78r4 vdeiqqnhksFZJgYzTSm4Abg58rbi6lRA4N4O/orYtM8d9DtxaarEUtPxIcwZrJGnIXsu tC/L1DzDenSkd/wldqRBvsHFQmn8nIZoKljZdtufECCAceQ7/0iYeqk9FxdTBENzRaP2 pvwg== 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=JDxwondAh/OUHugni3ivKWRUI1pwMRnCsBuB/co2xpE=; b=J9Us7QMdBJzECFXnSg577GYb7iRhOG+tDBsdUVlyEwX0InxuESdvurkY2+xbZqschW YO7+5bxI0a4vs2Jmr83nje4MdtSdd94rgg871HdnEpo0+c2izFykNmWVRcr8o1hV6F67 AvNxlCYL1mtHN2J1G2IJCxZg5xFxsmUtDH6J5iy8WIcHQVdnt6oB9woFAZNeb/62ayTi Pook9F0fplQ2BnDGWRyyNhrOdR3yz/CStEgQJT7cCXmEAnbA0qQyLXZt/w2yZKsYoaL/ fOg2NMomwvFvyDKMbGI5q8lnuIm3Kdz8tXq7wcoqJEH+E3F9RWCriDmYVcRSRiWO5v9S zxGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=TgERYlQJ; 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=canonical.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020a63ae0b000000b00534792ee482si2802760pgf.758.2023.05.21.01.52.37; Sun, 21 May 2023 01:52:49 -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=@canonical.com header.s=20210705 header.b=TgERYlQJ; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbjEUIba (ORCPT + 99 others); Sun, 21 May 2023 04:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbjEUI2W (ORCPT ); Sun, 21 May 2023 04:28:22 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7EA8ED for ; Sun, 21 May 2023 01:28:21 -0700 (PDT) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 888BF3F4F7 for ; Sun, 21 May 2023 08:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684657698; bh=JDxwondAh/OUHugni3ivKWRUI1pwMRnCsBuB/co2xpE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TgERYlQJWvrZw7gHn3ucr5v6Nsd0NPB6uVbqs6k+qlDRmOiBwA+YCgNvgKKN2htlj Lglx3xdXLUG+JjpvwJOL2XDX88f4LQc6C12su5kUVlO8wIOkprSj39FAH1dCBu1HJS BFD+gl1ECGerPKif+P5j6wuIlTgkCsR0R8j4T+8kDxuVs3KUuF4FpMPLnehtEcRWk4 yWHy+ZV02QDXg1le5Gulw5oES5qrEbkHF8kNaxHyRKbpb65rSsQCOH4FjYe7G2fvZC LDotCl7ELbaD99OHxLBepkHJmAq1952gy9yymZNgPUMNJtofHVujJCu/Dy6u2NAbLU KQ3EZBc0ExEZQ== Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-510b714821fso3139021a12.1 for ; Sun, 21 May 2023 01:28:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684657698; x=1687249698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JDxwondAh/OUHugni3ivKWRUI1pwMRnCsBuB/co2xpE=; b=JadZMG4DvCfDwoJQFoTGOVrR/35faz6whgBul6CeP2erxJhd1Wsn0VPzKPNbrU3LY1 MJCDdU/wu5xcQ/DKajqdagMezILqPaHYrYAmc1KLbocBj2SfBS38vlvNyrMc7dyu1aE7 g8v5Zk85oyQuPamgxte/Fneg3xuCh8Q3/9yRoXQNg6HgXtUYPm2VkjYt5pS4FoOlZd/q ouDjoR3XcSWq+sN6Liha8pRINGXLZ8y3BW8ZZSMWRifoHxk0alcHNddo1TbmuPHU1QOM k93ywdY83CdIrhOZX/Si+vUPJLaHA7N6KpTSrnqYIdcLmof/MTcHeosykQpQ19s6Oum6 0aUg== X-Gm-Message-State: AC+VfDyeWbfAOo/Rsr5BgJBrjakxTptXb2hveb/qDX72lQNuYrCn0jaY L+rp8hiN2kOwcCJEI+vNYzHFP/g5epmZWJpNhgoCZPxSZyeX3hkGwi8XQbwamW5YJnkrpJe7PMm fgrj3xS/zACFFxQgCWnZsRznP9PR6TAVkIjglD4QAZQ== X-Received: by 2002:a50:ed09:0:b0:50c:161b:9154 with SMTP id j9-20020a50ed09000000b0050c161b9154mr6988440eds.11.1684657698395; Sun, 21 May 2023 01:28:18 -0700 (PDT) X-Received: by 2002:a50:ed09:0:b0:50c:161b:9154 with SMTP id j9-20020a50ed09000000b0050c161b9154mr6988428eds.11.1684657698143; Sun, 21 May 2023 01:28:18 -0700 (PDT) Received: from righiandr-XPS-13-7390.homenet.telecomitalia.it (host-87-10-127-160.retail.telecomitalia.it. [87.10.127.160]) by smtp.gmail.com with ESMTPSA id z17-20020aa7cf91000000b004c2158e87e6sm1656646edx.97.2023.05.21.01.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 01:28:17 -0700 (PDT) From: Andrea Righi To: Miklos Szeredi Cc: Amir Goldstein , linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] ovl: validate superblock in OVL_FS() Date: Sun, 21 May 2023 10:28:13 +0200 Message-Id: <20230521082813.17025-4-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230521082813.17025-1-andrea.righi@canonical.com> References: <20230521082813.17025-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766493173360621801?= X-GMAIL-MSGID: =?utf-8?q?1766493173360621801?= When CONFIG_OVERLAY_FS_DEBUG is enabled add an explicit check to make sure that OVL_FS() is always used with a valid overlayfs superblock. Otherwise trigger a WARN_ON_ONCE(). Reviewed-by: Amir Goldstein Signed-off-by: Andrea Righi --- fs/overlayfs/ovl_entry.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h index b32c38fdf3c7..e156649d9c71 100644 --- a/fs/overlayfs/ovl_entry.h +++ b/fs/overlayfs/ovl_entry.h @@ -97,8 +97,20 @@ static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs) extern struct file_system_type ovl_fs_type; +static inline bool is_ovl_fs_sb(struct super_block *sb) +{ + return sb->s_type == &ovl_fs_type; +} + +#ifdef CONFIG_OVERLAY_FS_DEBUG +#define OVL_VALIDATE_SB(__sb) WARN_ON_ONCE(!is_ovl_fs_sb(__sb)) +#else +#define OVL_VALIDATE_SB(__sb) +#endif + static inline struct ovl_fs *OVL_FS(struct super_block *sb) { + OVL_VALIDATE_SB(sb); return (struct ovl_fs *)sb->s_fs_info; }