Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2161057ybv; Fri, 21 Feb 2020 10:03:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyds7oYoNrHit/8R91k84iQSmySB9xqDd8/ZQVZyPF18/YEhtCwbSf3hbZBTmLUNezpk+Jc X-Received: by 2002:a9d:6b84:: with SMTP id b4mr29548630otq.190.1582308180247; Fri, 21 Feb 2020 10:03:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582308180; cv=none; d=google.com; s=arc-20160816; b=CGCfpoV42atSbDC0HNAt6b4rr209ZLA+3pjw4IUWtOm10g0HDzCaY1RemNc5afPzp+ B+G4dFddHQDKIjsLmhFabzZr6Tb7QDFD8/EQTodbTfwPqabVW+Bb0yF7WVAh71U+aOwv ciMgX7T2RrWwuoya9YSngCWBhOdR7/yRCrW/x6lYF4EX+5UjGnNw3hKqxSKw3Yd9GNcN fgnzOrflMv3Q3Dp/A2yMArziipl5zdQZd/DZsp0ji3rkKYjq/m+h3oOOWPSs1C+sqh1I 1KHUw9iLYAm9WtF7pzYDDWntZGDuaKuokEZz/JaJ/7uh+5FrYQ39lS/RHFV/61QMC2pz ZhCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=lIl029QxOv3lUsZSV0uRKyqp9AfjU/t4KKE3QbkzNGc=; b=ZBHLbiLahuagCtQ/kT/8YtLi7jnHyQBOQ+XvHvTh70BR3inz/329rURLLae5EotNN7 5HD9ukwYQuLBs+jVxXAU5Leh1oCrbNpxw96lZ4embThmmutr56HIflG4C1SmZ7rejpVK tv1KJXuEb1028xzCzjOQPUpppC9aMB0NgBZVarGz9ib3h5pHJqjNrmcHJajL3d59prp9 rZAavAk7DsSE0Dy9lrnzxKpwmUJrTBwewzxafqqWF2iuCeTO+Isa23pZ86/da6WcTFTE EexJLIcVvxXm7YJN8JxApEyKCl1kME8yjvvEcXqaMVALPKBmvWIz76k4paoxfVrCIIgT j0mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ot5W/cbg"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p16si1881089oto.287.2020.02.21.10.02.48; Fri, 21 Feb 2020 10:03:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ot5W/cbg"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729416AbgBUSCZ (ORCPT + 99 others); Fri, 21 Feb 2020 13:02:25 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:31367 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726066AbgBUSCY (ORCPT ); Fri, 21 Feb 2020 13:02:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582308143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lIl029QxOv3lUsZSV0uRKyqp9AfjU/t4KKE3QbkzNGc=; b=Ot5W/cbgms++nCATUTd2/aG3YT38XODFh0csSn9nTbfVKqVuxF/1qselfj8rGkKrCIVyiL YMXOmhKu1ySv8qlDL2+ACS1JkO54gWiDkXFhPTKbKNEBwVHFgdEDbDcAU2C+EFhfcv/shl i1RtOyGz81QTjPBtRXZb9kmkKFauVe0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-alKxphWwM2y0ny3l0mGNuA-1; Fri, 21 Feb 2020 13:02:22 -0500 X-MC-Unique: alKxphWwM2y0ny3l0mGNuA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D2608017DF; Fri, 21 Feb 2020 18:02:20 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-122-163.rdu2.redhat.com [10.10.122.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0FFD2708E; Fri, 21 Feb 2020 18:02:18 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 04/17] watch_queue: Introduce a non-repeating system-unique superblock ID [ver #17] From: David Howells To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, raven@themaw.net, mszeredi@redhat.com, christian@brauner.io, jannh@google.com, darrick.wong@oracle.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 21 Feb 2020 18:02:18 +0000 Message-ID: <158230813823.2185128.2640121651515347574.stgit@warthog.procyon.org.uk> In-Reply-To: <158230810644.2185128.16726948836367716086.stgit@warthog.procyon.org.uk> References: <158230810644.2185128.16726948836367716086.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.21 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce an (effectively) non-repeating system-unique superblock ID that can be used to determine that two object are in the same superblock without risking reuse of the ID in the meantime (as is possible with device IDs). The ID is time-based to make it harder to use it as a covert communications channel. In future patches, this ID will be used to tag superblock notification messages. It will also be made queryable. Signed-off-by: David Howells --- fs/super.c | 24 ++++++++++++++++++++++++ include/linux/fs.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/fs/super.c b/fs/super.c index cd352530eca9..a63073e6127e 100644 --- a/fs/super.c +++ b/fs/super.c @@ -44,6 +44,8 @@ static int thaw_super_locked(struct super_block *sb); static LIST_HEAD(super_blocks); static DEFINE_SPINLOCK(sb_lock); +static u64 sb_last_identifier; +static u64 sb_identifier_offset; static char *sb_writers_name[SB_FREEZE_LEVELS] = { "sb_writers", @@ -188,6 +190,27 @@ static void destroy_unused_super(struct super_block *s) destroy_super_work(&s->destroy_work); } +/* + * Generate a unique identifier for a superblock. + */ +static void generate_super_id(struct super_block *s) +{ + u64 id = ktime_to_ns(ktime_get()); + + spin_lock(&sb_lock); + + id += sb_identifier_offset; + if (id <= sb_last_identifier) { + id = sb_last_identifier + 1; + sb_identifier_offset = sb_last_identifier - id; + } + + sb_last_identifier = id; + spin_unlock(&sb_lock); + + s->s_unique_id = id; +} + /** * alloc_super - create new superblock * @type: filesystem type superblock should belong to @@ -273,6 +296,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, goto fail; if (list_lru_init_memcg(&s->s_inode_lru, &s->s_shrink)) goto fail; + generate_super_id(s); return s; fail: diff --git a/include/linux/fs.h b/include/linux/fs.h index 3cd4fe6b845e..9de6bfe41016 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1548,6 +1548,9 @@ struct super_block { spinlock_t s_inode_wblist_lock; struct list_head s_inodes_wb; /* writeback inodes */ + + /* Superblock event notifications */ + u64 s_unique_id; } __randomize_layout; /* Helper functions so that in most cases filesystems will