From patchwork Mon Apr 26 07:01:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Mikhalitsyn X-Patchwork-Id: 1470208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mihalicyn.com header.i=@mihalicyn.com header.a=rsa-sha256 header.s=mihalicyn header.b=ZXq0ISsf; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FTG6G0gN0z9sX2; Mon, 26 Apr 2021 17:01:58 +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 1lavFf-0006m1-H2; Mon, 26 Apr 2021 07:01:51 +0000 Received: from mail-lf1-f46.google.com ([209.85.167.46]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lavFd-0006lu-4u for kernel-team@lists.ubuntu.com; Mon, 26 Apr 2021 07:01:49 +0000 Received: by mail-lf1-f46.google.com with SMTP id r128so59685704lff.4 for ; Mon, 26 Apr 2021 00:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=y5g1HLNcGQ0e8bpk1BMrXZID+uneVTuF2bg8cTMnYGg=; b=ZXq0ISsfB5Cf9iA5k/Rn553kcZTkMbeOOnGppzegUr2XGPBGVhtAcyQsAYnK9YSZVo 4MQa5ZFA4FDGHx3depsxpVISd1nVM7EMSi9dRCDjpBt7ToLtc2sIUZ8TBqUuaNQ/+v2W z9jjN01FNagy5utUY0x89KTXi8hMwbQTucbQg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=y5g1HLNcGQ0e8bpk1BMrXZID+uneVTuF2bg8cTMnYGg=; b=gw+yQQT5AGrhuEOLig5iO6muMotlANq5H+XMIsnZIdxoK2cDthtA/oje13OBYUn0XM 0AesN84sagVeAzkdcTSybZqBWb6znTJAxufBQTMsZh8no2weRIzJvnahuKriFNiB/YZx ULoauUgxh+Opa49PNjUC3pTYWaP1ziJLBWRQ08b8TgvE35BP8woJFRg2Qjgt1DUq39JH CFc3FFUy0BXA78B7NtJbeVp4MhCup+QHQEsycMGmdj4tzx8hoEb5pZa8ptJLx9iWVJhL B01V3xHdcepLV8GFfcHhy6L/kJ7BT446whLGVMRajrhGJbNrQ2PBb7GRJyHJHGTgJJl1 RcVw== X-Gm-Message-State: AOAM532wkcZLCC3wIEpFC78MMUjv8PEBP7e43Djc6C96Cy7AKMyLchnZ TTRltHvq909iiDT4lf/m3Xz8y6s0Y+KVU0E6kTA= X-Google-Smtp-Source: ABdhPJw4D4OBlxVBierO+RMS5bZjKm1P/u6tXTb7P7mdvGAtlMphi+qTNS2WV2RkX4x1NsH8ZhGV+w== X-Received: by 2002:a05:6512:11c5:: with SMTP id h5mr3363329lfr.401.1619420507362; Mon, 26 Apr 2021 00:01:47 -0700 (PDT) Received: from alexm-laptop.lan ([95.165.169.204]) by smtp.gmail.com with ESMTPSA id a16sm1425960ljp.15.2021.04.26.00.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 00:01:46 -0700 (PDT) From: alexander@mihalicyn.com To: kernel-team@lists.ubuntu.com Subject: [PATCH] UBUNTU: SAUCE: overlayfs: fix incorrect mnt_id of files opened from map_files Date: Mon, 26 Apr 2021 10:01:39 +0300 Message-Id: <20210426070139.21781-1-alexander@mihalicyn.com> X-Mailer: git-send-email 2.30.2 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 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: Christian Brauner Cc: Stefan Bader Cc: Connor Kuehl Cc: Kleber Sacilotto de Souza Fixes: 58009298c6bd ("UBUNTU: SAUCE: overlayfs: allow with shiftfs as underlay") Signed-off-by: Alexander Mikhalitsyn --- fs/overlayfs/file.c | 17 +++++++++++++++++ fs/overlayfs/overlayfs.h | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 0d3ea0cf3e98..7e63eb52bb0d 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -351,6 +351,23 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma) vma->vm_file = file; fput(realfile); } else { + /* + * 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 + */ + ovl_vm_prfile_set(vma, file); + /* Drop reference count from previous vm_file value */ fput(file); } diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 5f0188807666..a4e6023b4fdb 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -442,3 +442,15 @@ int ovl_set_origin(struct dentry *dentry, struct dentry *lower, /* export.c */ extern const struct export_operations ovl_export_operations; + +/* handle vma->vm_prfile */ +static inline 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 +}