From patchwork Fri Aug 5 06:32:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1663917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=IzeP/Nhn; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LzbPW34MFz9s1l for ; Fri, 5 Aug 2022 16:32:47 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oJqsv-0001Di-4w; Fri, 05 Aug 2022 06:32:37 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oJqss-00019O-0y for kernel-team@lists.ubuntu.com; Fri, 05 Aug 2022 06:32:34 +0000 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-0.canonical.com (Postfix) with ESMTPS id ABBFE3F136 for ; Fri, 5 Aug 2022 06:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659681153; bh=tdIExH8VveL2uPbOjnzB9O0RCSgF/0ciPg+j3Prw25c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IzeP/NhnjTCCvP1T7S6ssl7p+NZuyzqCTRmnTji3lZZ1FM3ng+3v2XXxuGMPF94w/ Nw/+Muyk19HYqXtw08x9LV1R7nZwwXKHA7OZ5LMayRJmtIHUXTG8nmKn2P1wPw+Qgo IdWNw4c5Xn7/9hc+MIfakz2D/qU5gBvLQhMrIbSccIT8djq7AeE2BlJugXxRnqRAVB TGhyC67AVpkX1dcROYi7JPWKhUCO+AI9xONd1kq9ruD1DJP1aLWIQd7o9I1KytvUH6 aMOAa63TUNcA742/dBZGoh+HQxN3xXBCRHwRSYdMG88HSTGpggMgcpJPK4mWxtZ+8d ZbeCoXj4G7i8A== Received: by mail-ed1-f72.google.com with SMTP id i5-20020a05640242c500b0043e50334109so1024578edc.1 for ; Thu, 04 Aug 2022 23:32:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=tdIExH8VveL2uPbOjnzB9O0RCSgF/0ciPg+j3Prw25c=; b=EsODfJ2CLMDVklKUr6dNy7hA8Zq3d34lvYAUN2pU2Yn/En6yi7mrTz0hDo+SuQMJa4 PcGc/RT2kZnqBgj5fdUaydAyXqxzcul+0dGvB5oLfjWu06joZv7D/aXvNahFF1IXAHz2 +IAkKcIL9TMpcD6N3BM2auqzcSevKnvBIkP757GC4diKwW97AC4b3iSNXwjId6ZVpa33 XPaYdnhicRylBtw53ySeqcfwwgqI3Uc0flNprxHntxZ7S3NfgZTkfYLwnmK3yMWQ9OVd q+oID8zdwuRvy4R0XuTKJOZwYcCpdPTqndvCLNrzb8JqZ+Hf5Plx6QwUKEiUTSMJpoLh s1KQ== X-Gm-Message-State: ACgBeo2LgYqg3efOCNLjLXEbBG3XFflrvkc0AkKdmDW/gunVOgZf400u dpIYuaXJxR1XsrDpJOcNPLIwr7G2U7UaODDtv+DHVQcjpMu+ZMNF66lgQF4w6R0qhMRmannCXQs 3jqnSFQ+kUYev/XMWfq6GMNfSa1Ap/72WokcNxIWn0w== X-Received: by 2002:a17:907:b590:b0:730:9e4c:3d5f with SMTP id qx16-20020a170907b59000b007309e4c3d5fmr4268269ejc.169.1659681148777; Thu, 04 Aug 2022 23:32:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR5zdLvdVNUU0nsWmkxy0MexJcPn1HUDkKTUij8OopNSxrkJjR+JHtGnINxXKzS5DFZyxMKSuA== X-Received: by 2002:a17:907:b590:b0:730:9e4c:3d5f with SMTP id qx16-20020a170907b59000b007309e4c3d5fmr4268258ejc.169.1659681148496; Thu, 04 Aug 2022 23:32:28 -0700 (PDT) Received: from arighi-desktop.homenet.telecomitalia.it ([2001:67c:1560:8007::aac:c1b6]) by smtp.gmail.com with ESMTPSA id eo12-20020a056402530c00b0042de3d661d2sm1568022edb.1.2022.08.04.23.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 23:32:28 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [J/hwe-5.17][PATCH 2/2] UBUNTU: SAUCE: overlayfs: fix incorrect mnt_id of files opened from map_files Date: Fri, 5 Aug 2022 08:32:14 +0200 Message-Id: <20220805063214.32432-6-andrea.righi@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220805063214.32432-1-andrea.righi@canonical.com> References: <20220805063214.32432-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexander Mikhalitsyn Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Alexander Mikhalitsyn BugLink: https://bugs.launchpad.net/bugs/1983640 The hack was introduced in ("UBUNTU: SAUCE: overlayfs: allow with shiftfs as underlay") and it broke checkpoint/restore of docker contains: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1857257 The following script can be used to trigger the issue: #!/bin/bash cat > test.py << EOF import sys f = open("/proc/self/maps") for l in f.readlines(): if "python" not in l: continue print(l) s = l.split() start, end = s[0].split("-") fname = s[-1] print(start, end, fname) break else: sys.exit(1) test_file1 = open(fname) test_file2 = open("/proc/self/map_files/%s-%s" % (start, end)) fdinfo1 = open("/proc/self/fdinfo/%d" % test_file1.fileno()).read() fdinfo2 = open("/proc/self/fdinfo/%d" % test_file2.fileno()).read() if fdinfo1 != fdinfo2: print("FAIL") print(test_file1) print(fdinfo1) print(test_file2) print(fdinfo2) sys.exit(1) print("PASS") EOF sudo docker run -it --privileged --rm -v `pwd`:/mnt python python /mnt/test.py Thanks to Andrei Vagin for the reproducer and investigation of this problem. [refactoring to drop dependency of AUFS] Signed-off-by: Alexander Mikhalitsyn Signed-off-by: Andrea Righi --- fs/overlayfs/file.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 835e99b2e080..c0bae39ae4e2 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -490,6 +490,32 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) return ret; } +/* + * In map_files_get_link() (fs/proc/base.c) + * we need to determine correct path from overlayfs. + * But real_mount(realfile->f_path.mnt) may be not + * equal to real_mount(file->f_path.mnt). In such case + * fdinfo of the same file which was opened from + * /proc//map_files/... and "usual" path + * will show different mnt_id. + * + * We solve issue like in aufs by using additional + * field on struct vm_area_struct called "vm_prfile" + * which is used only for fdinfo/"printing" needs. + * + * See also mm/prfile.c + */ +static void ovl_vm_prfile_set(struct vm_area_struct *vma, + struct file *file) +{ + get_file(file); + vma->vm_prfile = file; +#ifndef CONFIG_MMU + get_file(file); + vma->vm_region->vm_prfile = file; +#endif +} + static int ovl_mmap(struct file *file, struct vm_area_struct *vma) { struct file *realfile = file->private_data; @@ -507,6 +533,10 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma) old_cred = ovl_override_creds(file_inode(file)->i_sb); ret = call_mmap(vma->vm_file, vma); revert_creds(old_cred); + + if (!ret) + ovl_vm_prfile_set(vma, file); + ovl_file_accessed(file); return ret;