From patchwork Sat May 20 18:41:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 9626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp524599vqo; Sat, 20 May 2023 12:18:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ZXr/MY0DvXKRA+LAdFvUplpCsSzbzmOw7+u6+1rvKa3MawJTSn7ugGSLye1YZex2ghSfp X-Received: by 2002:a05:6a00:2408:b0:643:7fcf:836d with SMTP id z8-20020a056a00240800b006437fcf836dmr7685535pfh.25.1684610315902; Sat, 20 May 2023 12:18:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684610315; cv=none; d=google.com; s=arc-20160816; b=B/mBCniXplWK8rMr6MyjRSEI1tMCVlUwVxPTlxWo8PkFdsWZdP49Ec4l9Dar/AizC7 t+pJL+e9WJbjsyKX0yMpHv37FlH8iIZyqGChLOHVtSGHHVlBiDlNVjSmbx2XDQT/Ng7A dQXedLAlh6RWMy0LqdhFUqGBvbz5jyzN0UbqjWqjyYAfLSqw1Me4JowDTtINyUmT28+s T9SdSm5C3yckrdpZmxo1LTyy5X7T7vqbQsONI6SlkalqW8XXhTbb5EGbLt8xx++6fgkJ mIR6SUm91bWDnbgnMt97A1bci69GpsdNNG+SnA619zD51fHxWUgqLE2clxO9wdgxBi3D Nf8g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=C/qPwdzE2G8bmRC9cyFwLOXABhp9l9ZfW4+oqS1kXSE=; b=q4EPFr6rDJ1RXub5J/rdxO+0c9mA5ay5M4hDQsjXlBTosvFS1k8Vf1RSeekvVivK5I 4uOVBL+aV4mtdea7I8WCNVvqFZwz83qxh7TuuXEwoM0xjfQeAJ8jsODjmyzOBOMiJ8qx wmZnwFDFqQJJ3ghI2skN+ECF54MA+TuCUmZtlJsprtOC+YBOhX/SCGBwBOKr8wLEQ3vG SuS1pl6UKtykIW4sxL4B3NSKBI7cuxIvnmloJ8TnDvomlyjBNfiTFIuWL2IYgFJREuyh P9JqmVKf+G1kZYjwtGfxPJ6kMPquR/zzTNdu9YJM2KvaGH5gNjVQeBzejOJnu7d/i4fS KUhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=XKXu1tvI; 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 d196-20020a621dcd000000b0064cecf7b983si1296606pfd.143.2023.05.20.12.18.21; Sat, 20 May 2023 12:18:35 -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=XKXu1tvI; 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 S231912AbjETSlX (ORCPT + 99 others); Sat, 20 May 2023 14:41:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231296AbjETSlV (ORCPT ); Sat, 20 May 2023 14:41:21 -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 F2D929D for ; Sat, 20 May 2023 11:41:19 -0700 (PDT) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (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 570AE3F22E for ; Sat, 20 May 2023 18:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684608078; bh=C/qPwdzE2G8bmRC9cyFwLOXABhp9l9ZfW4+oqS1kXSE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=XKXu1tvIPc358yamsTwgxwV0M0AR6Dz5xWkdMCR4vjO3W4DFtykUPcH3eg6KtVJa0 uAiHiKV2id5UnMOrpdCb75d0MEO+kjOPPimPVTxSFYd5NysHGeVVSVIFuZa0LlgQxT qt/gKoFaTU6W2GjWT1ULF9Sb7iHS+nZFql9JDo40mwBsdcWpIBOe0+ImLXRKw8n7sX NAp60+T0c59JbyoXpi1nKFBzpi2AhAkadnRSb2rOLDVcVmWAlbgM4KT3YMsQIYJrto wOAQsCw7usKj4L9nWmEYptxpUEoc/oB/pOrYRuy960sgsFKLjJDYmQL5i28pJUfP8B fDjPOlHqjiGAA== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-9663552473fso573785066b.1 for ; Sat, 20 May 2023 11:41:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684608078; x=1687200078; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=C/qPwdzE2G8bmRC9cyFwLOXABhp9l9ZfW4+oqS1kXSE=; b=koJ6xiwblK6nREO+rnX9SbXXbM80R7CuGCLu7fFVAkCXP2/jrfA5IaxqDMT50OjEY6 FdxG0eZMAK/poG9kwLfYZbv6ISgs420eQKianvECyZX6TbU/4mzfyxaDgUJM4hQuMVdv QdxT2sWbfnzk6mBYCNhqlu7Tn2S5gZT2eU5T2MT7UcqapLv+eI3wrU/EhKRkfVbeNWm1 ZoL0u4ge351T1vIRMMzOvZsedUq9lUaYB52nqD/z7Llmnr3lRPqFi0JmTo6YcHcwZa6e EiRvvu5zsUvcx69ab0eVYhSh5tmP3VDXvgVN8Kj9EpF/uoNIdmztOKKyKT30X78wohAq 4Nkw== X-Gm-Message-State: AC+VfDw1aaDSfUllIRgugxL4qfnpDJaww+fkcPUB3iQovW9mPly6Zgli VctFGIJVTLAgt6m/G0A5aWQf8eVJDHJj5tBS0eTqG89RE3a5VkyL1BVM1fHJhKxnEr09ce/cVPF YR+HEpayMPi7XF5wmzJWCWOIZlPgrTC/K8MqZM79ykQ== X-Received: by 2002:a17:906:4fd0:b0:94f:36a0:da45 with SMTP id i16-20020a1709064fd000b0094f36a0da45mr6744526ejw.29.1684608077966; Sat, 20 May 2023 11:41:17 -0700 (PDT) X-Received: by 2002:a17:906:4fd0:b0:94f:36a0:da45 with SMTP id i16-20020a1709064fd000b0094f36a0da45mr6744513ejw.29.1684608077668; Sat, 20 May 2023 11:41:17 -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 x6-20020a1709065ac600b009663115c8f8sm1046294ejs.152.2023.05.20.11.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 May 2023 11:41:17 -0700 (PDT) From: Andrea Righi To: Miklos Szeredi Cc: Amir Goldstein , linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/2] overlayfs: debugging check for valid superblock Date: Sat, 20 May 2023 20:41:12 +0200 Message-Id: <20230520184114.77725-1-andrea.righi@canonical.com> X-Mailer: git-send-email 2.39.2 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,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766441946579311770?= X-GMAIL-MSGID: =?utf-8?q?1766441946579311770?= OVL_FS() is used to get a struct ovl_fs from a sturct super_block, but we don't have any check to determine if the superblock is valid or not. This can lead to unexpected behaviors or bugs that are pretty hard to track down. Add an explicit WARN_ON_ONCE() check to OVL_FS() to make sure it's always used with a valid overlayfs superblock. To avoid enabling this additional pendatic check everywhere, introduce the new config option CONFIG_OVERLAY_FS_DEBUG, that can be used in the future also for other additional debugging checks. Maybe a nicer solution could be to return an error from OVL_FS() when it's used with an invalid superblock and propagate the error in the rest of overlayfs code, but for now having at least the possibility to trigger a warning can help to catch potential bugs in advance. Changelog (v1 -> v2): - replace BUG_ON() with WARN_ON_ONCE() - introduce CONFIG_OVERLAY_FS_DEBUG Andrea Righi (2): ovl: Kconfig: introduce CONFIG_OVERLAY_FS_DEBUG ovl: make consistent use of OVL_FS() fs/overlayfs/Kconfig | 9 +++++++++ fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/export.c | 10 +++++----- fs/overlayfs/inode.c | 8 ++++---- fs/overlayfs/namei.c | 2 +- fs/overlayfs/ovl_entry.h | 16 ++++++++++++++++ fs/overlayfs/super.c | 12 ++++++------ fs/overlayfs/util.c | 18 +++++++++--------- 8 files changed, 51 insertions(+), 26 deletions(-)