From patchwork Thu Apr 14 15:57:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1617312 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=RTyLl1sK; 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 4KfPJ10gBVz9sGf for ; Fri, 15 Apr 2022 01:58:09 +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 1nf1rA-0005KT-1a; Thu, 14 Apr 2022 15:58:04 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nf1r7-0005Jj-L4 for kernel-team@lists.ubuntu.com; Thu, 14 Apr 2022 15:58:01 +0000 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.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 66F7F3F312 for ; Thu, 14 Apr 2022 15:58:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1649951881; bh=hEEPazzy6L5RTcEoS0nnTmm8kRe7LKq/M+SoQ9JAx9k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RTyLl1sKJd5KBz30n6pUk4qWwhkwQfw+cedguX4G/2ClnXFB2Pltk9f0ZYiLvZbo3 1BbcwgwTIZ93kEP7Ro8N+/qTaz1mKyewNDWCJ5+iITV0+qU0OHutEjMeqlgRTw65vF BTkaEDS2S8U0hvGNLvUN1vyseZqViFcZ1NcfdbLynHPDAYlQZhVG2OWS7t5AcdoDvL YkQQxWJW/ycc7HonOPKhVPkoa+3xzmDUGYwYqDqovI6KDfRIqsr2traAEXD0y4y1PQ P/abNRy7PawUwr1WjRx+k9A1u76Z2FlG7b8BQ3/w0G2m0StmIT4Yn3xI1w1SSYy98U t8jZQy7y7b9KQ== Received: by mail-ed1-f71.google.com with SMTP id dm27-20020a05640222db00b0041d76d4f795so3291197edb.2 for ; Thu, 14 Apr 2022 08:58:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hEEPazzy6L5RTcEoS0nnTmm8kRe7LKq/M+SoQ9JAx9k=; b=nbYfeYQiQH9NogGSljH/brX9H+wOWSdfA1jbGeF7Kch4v00rK+r4rTQxYlvPuzL6Ms aUnwcDChsUebFEL6VbEGcWox9ikQ7wZxfcSAOpCyXkyFhaSF3CwMXTWQE5BcJ3wt/Jun 3dYkNwKudAYjXKi/8LGrWpRHg7/NezPoTlU60vKahSUSAzp/cK2DqtK5pqHvkEUXWtUZ KiK3ry9gjCwcS8XBsEbIfkl9WWs9fao6zAK6JUwOcdeZJEwlHg1Xb9Lajw8iHDFbWE++ 9BFMGwjNENde/AwFu8/V8jMtbbHDMslDAvm+63U5US3s9iqE8bjyqzl3aMDI+KypVMhE jpRA== X-Gm-Message-State: AOAM531L7uMrWgUBXT90s9Mk/XkxtvQCSbFU38nhjosp0y/qULcw6r5f TCas/qF84yTqa15G86BWlLmY3rf+u/TnywAuhwupzYBzS7JJ9rMwdMK6ySYZPvCROarNM/4MPlk DpqQzPbutKrfPG2W9Xxgodd8sL3y4Kw6LXR5bOqFSww== X-Received: by 2002:a17:906:d552:b0:6ec:9e3:f730 with SMTP id cr18-20020a170906d55200b006ec09e3f730mr2369461ejc.192.1649951880828; Thu, 14 Apr 2022 08:58:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfhFK5sinyQ85D5/Oox0D36N+B142/uhKVWptMJ6aHHtAFPerZU+kCLG7c8cJj3IyEz+w12g== X-Received: by 2002:a17:906:d552:b0:6ec:9e3:f730 with SMTP id cr18-20020a170906d55200b006ec09e3f730mr2369449ejc.192.1649951880611; Thu, 14 Apr 2022 08:58:00 -0700 (PDT) Received: from arighi-desktop.homenet.telecomitalia.it ([2001:67c:1560:8007::aac:c1b6]) by smtp.gmail.com with ESMTPSA id b11-20020a17090630cb00b006e83fb1e6b1sm758456ejb.100.2022.04.14.08.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 08:58:00 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][J/I][PATCH 1/1] UBUNTU: SAUCE: overlayfs: fix incorrect mnt_id of files opened from map_files Date: Thu, 14 Apr 2022 17:57:56 +0200 Message-Id: <20220414155756.249769-2-andrea.righi@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220414155756.249769-1-andrea.righi@canonical.com> References: <20220414155756.249769-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: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Alexander Mikhalitsyn BugLink: https://bugs.launchpad.net/bugs/1967924 BugLink: https://bugs.launchpad.net/bugs/1857257 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. Cc: Andrei Vagin Cc: Adrian Reber Cc: Christian Brauner Cc: Stefan Bader Cc: Kleber Sacilotto de Souza Cc: Krzysztof Kozlowski Fixes: d24b8a5 ("UBUNTU: SAUCE: overlayfs: allow with shiftfs as underlay") Signed-off-by: Alexander Mikhalitsyn Acked-by: Seth Forshee Acked-by: Stefan Bader Acked-by: Krzysztof Kozlowski Signed-off-by: Kelsey Skunberg [small refactoring to add the dependency of AUFS for vma->vm_prfile] Signed-off-by: Andrea Righi Acked-by: Kleber Sacilotto de Souza --- fs/overlayfs/file.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index d0c96ca0202e..362dd17b8a00 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -490,6 +490,41 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) return ret; } +#if IS_ENABLED(CONFIG_AUFS_FS) +/* + * 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 + /* Drop reference count from previous vm_file value */ + fput(file); +} +#else /* !CONFIG_AUFS_FS */ +static void ovl_vm_prfile_set(struct vm_area_struct *vma, + struct file *file) +{ +} +#endif/* CONFIG_AUFS_FS */ + static int ovl_mmap(struct file *file, struct vm_area_struct *vma) { struct file *realfile = file->private_data; @@ -507,6 +542,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;