sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget*/translations/zh_CN/filesystems/idmappingsmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/zh_TW/filesystems/idmappingsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/it_IT/filesystems/idmappingsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/ja_JP/filesystems/idmappingsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/ko_KR/filesystems/idmappingsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget*/translations/sp_SP/filesystems/idmappingsmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhD/var/lib/git/docbuild/linux/Documentation/filesystems/idmappings.rsthKubhsection)}(hhh](htitle)}(h Idmappingsh]h Idmappings}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hXMost filesystem developers will have encountered idmappings. They are used when reading from or writing ownership to disk, reporting ownership to userspace, or for permission checking. This document is aimed at filesystem developers that want to know how idmappings work.h]hXMost filesystem developers will have encountered idmappings. They are used when reading from or writing ownership to disk, reporting ownership to userspace, or for permission checking. This document is aimed at filesystem developers that want to know how idmappings work.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(h Formal notesh]h Formal notes}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhK ubh)}(hAn idmapping is essentially a translation of a range of ids into another or the same range of ids. The notational convention for idmappings that is widely used in userspace is::h]hAn idmapping is essentially a translation of a range of ids into another or the same range of ids. The notational convention for idmappings that is widely used in userspace is:}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh literal_block)}(hu:k:rh]hu:k:r}hhsbah}(h]h ]h"]h$]h&]hhuh1hhhhKhhhhubh)}(hXf``u`` indicates the first element in the upper idmapset ``U`` and ``k`` indicates the first element in the lower idmapset ``K``. The ``r`` parameter indicates the range of the idmapping, i.e. how many ids are mapped. From now on, we will always prefix ids with ``u`` or ``k`` to make it clear whether we're talking about an id in the upper or lower idmapset.h](hliteral)}(h``u``h]hu}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh3 indicates the first element in the upper idmapset }(hjhhhNhNubj )}(h``U``h]hU}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``k``h]hk}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh3 indicates the first element in the lower idmapset }(hjhhhNhNubj )}(h``K``h]hK}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. The }(hjhhhNhNubj )}(h``r``h]hr}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh{ parameter indicates the range of the idmapping, i.e. how many ids are mapped. From now on, we will always prefix ids with }(hjhhhNhNubj )}(h``u``h]hu}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }(hjhhhNhNubj )}(h``k``h]hk}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhU to make it clear whether we’re talking about an id in the upper or lower idmapset.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hMTo see what this looks like in practice, let's take the following idmapping::h]hNTo see what this looks like in practice, let’s take the following idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h u22:k10000:r3h]h u22:k10000:r3}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKhhhhubh)}(h.and write down the mappings it will generate::h]h-and write down the mappings it will generate:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h)u22 -> k10000 u23 -> k10001 u24 -> k10002h]h)u22 -> k10000 u23 -> k10001 u24 -> k10002}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhK hhhhubh)}(hXFrom a mathematical viewpoint ``U`` and ``K`` are well-ordered sets and an idmapping is an order isomorphism from ``U`` into ``K``. So ``U`` and ``K`` are order isomorphic. In fact, ``U`` and ``K`` are always well-ordered subsets of the set of all possible ids usable on a given system.h](hFrom a mathematical viewpoint }(hjhhhNhNubj )}(h``U``h]hU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``K``h]hK}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhE are well-ordered sets and an idmapping is an order isomorphism from }(hjhhhNhNubj )}(h``U``h]hU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh into }(hjhhhNhNubj )}(h``K``h]hK}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. So }(hjhhhNhNubj )}(h``U``h]hU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }hjsbj )}(h``K``h]hK}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh are order isomorphic. In fact, }(hjhhhNhNubj )}(h``U``h]hU}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }hjsbj )}(h``K``h]hK}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhY are always well-ordered subsets of the set of all possible ids usable on a given system.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK$hhhhubh)}(hLooking at this mathematically briefly will help us highlight some properties that make it easier to understand how we can translate between idmappings. For example, we know that the inverse idmapping is an order isomorphism as well::h]hLooking at this mathematically briefly will help us highlight some properties that make it easier to understand how we can translate between idmappings. For example, we know that the inverse idmapping is an order isomorphism as well:}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hhhhubh)}(h)k10000 -> u22 k10001 -> u23 k10002 -> u24h]h)k10000 -> u22 k10001 -> u23 k10002 -> u24}hjvsbah}(h]h ]h"]h$]h&]hhuh1hhhhK-hhhhubh)}(hXGiven that we are dealing with order isomorphisms plus the fact that we're dealing with subsets we can embed idmappings into each other, i.e. we can sensibly translate between different idmappings. For example, assume we've been given the three idmappings::h]hXGiven that we are dealing with order isomorphisms plus the fact that we’re dealing with subsets we can embed idmappings into each other, i.e. we can sensibly translate between different idmappings. For example, assume we’ve been given the three idmappings:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK1hhhhubh)}(h;1. u0:k10000:r10000 2. u0:k20000:r10000 3. u0:k30000:r10000h]h;1. u0:k10000:r10000 2. u0:k20000:r10000 3. u0:k30000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhK6hhhhubh)}(hand id ``k11000`` which has been generated by the first idmapping by mapping ``u1000`` from the upper idmapset down to ``k11000`` in the lower idmapset.h](hand id }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh< which has been generated by the first idmapping by mapping }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh! from the upper idmapset down to }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh in the lower idmapset.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK:hhhhubh)}(hXBecause we're dealing with order isomorphic subsets it is meaningful to ask what id ``k11000`` corresponds to in the second or third idmapping. The straightforward algorithm to use is to apply the inverse of the first idmapping, mapping ``k11000`` up to ``u1000``. Afterwards, we can map ``u1000`` down using either the second idmapping mapping or third idmapping mapping. The second idmapping would map ``u1000`` down to ``k21000``. The third idmapping would map ``u1000`` down to ``k31000``.h](hVBecause we’re dealing with order isomorphic subsets it is meaningful to ask what id }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh corresponds to in the second or third idmapping. The straightforward algorithm to use is to apply the inverse of the first idmapping, mapping }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh up to }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. Afterwards, we can map }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhk down using either the second idmapping mapping or third idmapping mapping. The second idmapping would map }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh down to }(hjhhhNhNubj )}(h ``k21000``h]hk21000}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh . The third idmapping would map }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh down to }hjsbj )}(h ``k31000``h]hk31000}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK=hhhhubh)}(hCIf we were given the same task for the following three idmappings::h]hBIf we were given the same task for the following three idmappings:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKEhhhhubh)}(h71. u0:k10000:r10000 2. u0:k20000:r200 3. u0:k30000:r300h]h71. u0:k10000:r10000 2. u0:k20000:r200 3. u0:k30000:r300}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKGhhhhubh)}(hXwe would fail to translate as the sets aren't order isomorphic over the full range of the first idmapping anymore (However they are order isomorphic over the full range of the second idmapping.). Neither the second or third idmapping contain ``u1000`` in the upper idmapset ``U``. This is equivalent to not having an id mapped. We can simply say that ``u1000`` is unmapped in the second and third idmapping. The kernel will report unmapped ids as the overflowuid ``(uid_t)-1`` or overflowgid ``(gid_t)-1`` to userspace.h](hwe would fail to translate as the sets aren’t order isomorphic over the full range of the first idmapping anymore (However they are order isomorphic over the full range of the second idmapping.). Neither the second or third idmapping contain }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh in the upper idmapset }(hjhhhNhNubj )}(h``U``h]hU}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhH. This is equivalent to not having an id mapped. We can simply say that }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhg is unmapped in the second and third idmapping. The kernel will report unmapped ids as the overflowuid }(hjhhhNhNubj )}(h ``(uid_t)-1``h]h (uid_t)-1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or overflowgid }(hjhhhNhNubj )}(h ``(gid_t)-1``h]h (gid_t)-1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh to userspace.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKKhhhhubh)}(hThe algorithm to calculate what a given id maps to is pretty simple. First, we need to verify that the range can contain our target id. We will skip this step for simplicity. After that if we want to know what ``id`` maps to we can do simple calculations:h](hThe algorithm to calculate what a given id maps to is pretty simple. First, we need to verify that the range can contain our target id. We will skip this step for simplicity. After that if we want to know what }(hjhhhNhNubj )}(h``id``h]hid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh' maps to we can do simple calculations:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKShhhhubh bullet_list)}(hhh](h list_item)}(h?If we want to map from left to right:: u:k:r id - u + k = n h](h)}(h&If we want to map from left to right::h]h%If we want to map from left to right:}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKXhj-ubh)}(hu:k:r id - u + k = nh]hu:k:r id - u + k = n}hj?sbah}(h]h ]h"]h$]h&]hhuh1hhhhKZhj-ubeh}(h]h ]h"]h$]h&]uh1j+hj(hhhhhNubj,)}(h?If we want to map from right to left:: u:k:r id - k + u = n h](h)}(h&If we want to map from right to left::h]h%If we want to map from right to left:}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK]hjSubh)}(hu:k:r id - k + u = nh]hu:k:r id - k + u = n}hjesbah}(h]h ]h"]h$]h&]hhuh1hhhhK_hjSubeh}(h]h ]h"]h$]h&]uh1j+hj(hhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1j&hhhKXhhhhubh)}(hInstead of "left to right" we can also say "down" and instead of "right to left" we can also say "up". Obviously mapping down and up invert each other.h]hInstead of “left to right” we can also say “down” and instead of “right to left” we can also say “up”. Obviously mapping down and up invert each other.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKbhhhhubh)}(hVTo see whether the simple formulas above work, consider the following two idmappings::h]hUTo see whether the simple formulas above work, consider the following two idmappings:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKehhhhubh)}(h)1. u0:k20000:r10000 2. u500:k30000:r10000h]h)1. u0:k20000:r10000 2. u500:k30000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKhhhhhubh)}(hAssume we are given ``k21000`` in the lower idmapset of the first idmapping. We want to know what id this was mapped from in the upper idmapset of the first idmapping. So we're mapping up in the first idmapping::h](hAssume we are given }(hjhhhNhNubj )}(h ``k21000``h]hk21000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh in the lower idmapset of the first idmapping. We want to know what id this was mapped from in the upper idmapset of the first idmapping. So we’re mapping up in the first idmapping:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKkhhhhubh)}(h5id - k + u = n k21000 - k20000 + u0 = u1000h]h5id - k + u = n k21000 - k20000 + u0 = u1000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKohhhhubh)}(hNow assume we are given the id ``u1100`` in the upper idmapset of the second idmapping and we want to know what this id maps down to in the lower idmapset of the second idmapping. This means we're mapping down in the second idmapping::h](hNow assume we are given the id }(hjhhhNhNubj )}(h ``u1100``h]hu1100}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh in the upper idmapset of the second idmapping and we want to know what this id maps down to in the lower idmapset of the second idmapping. This means we’re mapping down in the second idmapping:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKrhhhhubh)}(h8id - u + k = n u1100 - u500 + k30000 = k30600h]h8id - u + k = n u1100 - u500 + k30000 = k30600}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKwhhhhubeh}(h] formal-notesah ]h"] formal notesah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(h General notesh]h General notes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK{ubh)}(h}In the context of the kernel an idmapping can be interpreted as mapping a range of userspace ids into a range of kernel ids::h]h|In the context of the kernel an idmapping can be interpreted as mapping a range of userspace ids into a range of kernel ids:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjhhubh)}(huserspace-id:kernel-id:rangeh]huserspace-id:kernel-id:range}hj.sbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(hXzA userspace id is always an element in the upper idmapset of an idmapping of type ``uid_t`` or ``gid_t`` and a kernel id is always an element in the lower idmapset of an idmapping of type ``kuid_t`` or ``kgid_t``. From now on "userspace id" will be used to refer to the well known ``uid_t`` and ``gid_t`` types and "kernel id" will be used to refer to ``kuid_t`` and ``kgid_t``.h](hRA userspace id is always an element in the upper idmapset of an idmapping of type }(hj<hhhNhNubj )}(h ``uid_t``h]huid_t}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubh or }(hj<hhhNhNubj )}(h ``gid_t``h]hgid_t}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubhT and a kernel id is always an element in the lower idmapset of an idmapping of type }(hj<hhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubh or }hj<sbj )}(h ``kgid_t``h]hkgid_t}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubhI. From now on “userspace id” will be used to refer to the well known }(hj<hhhNhNubj )}(h ``uid_t``h]huid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubh and }(hj<hhhNhNubj )}(h ``gid_t``h]hgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubh4 types and “kernel id” will be used to refer to }(hj<hhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubh and }hj<sbj )}(h ``kgid_t``h]hkgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj<ubh.}(hj<hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXQThe kernel is mostly concerned with kernel ids. They are used when performing permission checks and are stored in an inode's ``i_uid`` and ``i_gid`` field. A userspace id on the other hand is an id that is reported to userspace by the kernel, or is passed by userspace to the kernel, or a raw device id that is written or read from disk.h](hThe kernel is mostly concerned with kernel ids. They are used when performing permission checks and are stored in an inode’s }(hjhhhNhNubj )}(h ``i_uid``h]hi_uid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``i_gid``h]hi_gid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh field. A userspace id on the other hand is an id that is reported to userspace by the kernel, or is passed by userspace to the kernel, or a raw device id that is written or read from disk.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hoNote that we are only concerned with idmappings as the kernel stores them not how userspace would specify them.h]hoNote that we are only concerned with idmappings as the kernel stores them not how userspace would specify them.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hFor the rest of this document we will prefix all userspace ids with ``u`` and all kernel ids with ``k``. Ranges of idmappings will be prefixed with ``r``. So an idmapping will be written as ``u0:k10000:r10000``.h](hDFor the rest of this document we will prefix all userspace ids with }(hjhhhNhNubj )}(h``u``h]hu}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and all kernel ids with }(hjhhhNhNubj )}(h``k``h]hk}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh-. Ranges of idmappings will be prefixed with }(hjhhhNhNubj )}(h``r``h]hr}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh%. So an idmapping will be written as }(hjhhhNhNubj )}(h``u0:k10000:r10000``h]hu0:k10000:r10000}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hFor example, within this idmapping, the id ``u1000`` is an id in the upper idmapset or "userspace idmapset" starting with ``u0``. And it is mapped to ``k11000`` which is a kernel id in the lower idmapset or "kernel idmapset" starting with ``k10000``.h](h+For example, within this idmapping, the id }(hjphhhNhNubj )}(h ``u1000``h]hu1000}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjpubhJ is an id in the upper idmapset or “userspace idmapset” starting with }(hjphhhNhNubj )}(h``u0``h]hu0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjpubh. And it is mapped to }(hjphhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjpubhS which is a kernel id in the lower idmapset or “kernel idmapset” starting with }(hjphhhNhNubj )}(h ``k10000``h]hk10000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjpubh.}(hjphhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXCA kernel id is always created by an idmapping. Such idmappings are associated with user namespaces. Since we mainly care about how idmappings work we're not going to be concerned with how idmappings are created nor how they are used outside of the filesystem context. This is best left to an explanation of user namespaces.h]hXEA kernel id is always created by an idmapping. Such idmappings are associated with user namespaces. Since we mainly care about how idmappings work we’re not going to be concerned with how idmappings are created nor how they are used outside of the filesystem context. This is best left to an explanation of user namespaces.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hYThe initial user namespace is special. It always has an idmapping of the following form::h]hXThe initial user namespace is special. It always has an idmapping of the following form:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hu0:k0:r4294967295h]hu0:k0:r4294967295}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(hSwhich is an identity idmapping over the full range of ids available on this system.h]hSwhich is an identity idmapping over the full range of ids available on this system.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hDOther user namespaces usually have non-identity idmappings such as::h]hCOther user namespaces usually have non-identity idmappings such as:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hu0:k10000:r10000h]hu0:k10000:r10000}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjhhubh)}(hXWhen a process creates or wants to change ownership of a file, or when the ownership of a file is read from disk by a filesystem, the userspace id is immediately translated into a kernel id according to the idmapping associated with the relevant user namespace.h]hXWhen a process creates or wants to change ownership of a file, or when the ownership of a file is read from disk by a filesystem, the userspace id is immediately translated into a kernel id according to the idmapping associated with the relevant user namespace.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(haFor instance, consider a file that is stored on disk by a filesystem as being owned by ``u1000``:h](hWFor instance, consider a file that is stored on disk by a filesystem as being owned by }(hj(hhhNhNubj )}(h ``u1000``h]hu1000}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(ubh:}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj')}(hhh](j,)}(hXHIf a filesystem were to be mounted in the initial user namespaces (as most filesystems are) then the initial idmapping will be used. As we saw this is simply the identity idmapping. This would mean id ``u1000`` read from disk would be mapped to id ``k1000``. So an inode's ``i_uid`` and ``i_gid`` field would contain ``k1000``. h]h)}(hXGIf a filesystem were to be mounted in the initial user namespaces (as most filesystems are) then the initial idmapping will be used. As we saw this is simply the identity idmapping. This would mean id ``u1000`` read from disk would be mapped to id ``k1000``. So an inode's ``i_uid`` and ``i_gid`` field would contain ``k1000``.h](hIf a filesystem were to be mounted in the initial user namespaces (as most filesystems are) then the initial idmapping will be used. As we saw this is simply the identity idmapping. This would mean id }(hjOhhhNhNubj )}(h ``u1000``h]hu1000}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjOubh& read from disk would be mapped to id }(hjOhhhNhNubj )}(h ``k1000``h]hk1000}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1j hjOubh. So an inode’s }(hjOhhhNhNubj )}(h ``i_uid``h]hi_uid}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjOubh and }(hjOhhhNhNubj )}(h ``i_gid``h]hi_gid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjOubh field would contain }(hjOhhhNhNubj )}(h ``k1000``h]hk1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjOubh.}(hjOhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjKubah}(h]h ]h"]h$]h&]uh1j+hjHhhhhhNubj,)}(hIf a filesystem were to be mounted with an idmapping of ``u0:k10000:r10000`` then ``u1000`` read from disk would be mapped to ``k11000``. So an inode's ``i_uid`` and ``i_gid`` would contain ``k11000``. h]h)}(hIf a filesystem were to be mounted with an idmapping of ``u0:k10000:r10000`` then ``u1000`` read from disk would be mapped to ``k11000``. So an inode's ``i_uid`` and ``i_gid`` would contain ``k11000``.h](h8If a filesystem were to be mounted with an idmapping of }(hjhhhNhNubj )}(h``u0:k10000:r10000``h]hu0:k10000:r10000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh then }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh# read from disk would be mapped to }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. So an inode’s }(hjhhhNhNubj )}(h ``i_uid``h]hi_uid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``i_gid``h]hi_gid}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh would contain }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j+hjHhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j&hhhKhjhhubeh}(h] general-notesah ]h"] general notesah$]h&]uh1hhhhhhhhK{ubh)}(hhh](h)}(hTranslation algorithmsh]hTranslation algorithms}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjOhhhhhKubh)}(hWe've already seen briefly that it is possible to translate between different idmappings. We'll now take a closer look how that works.h]hWe’ve already seen briefly that it is possible to translate between different idmappings. We’ll now take a closer look how that works.}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjOhhubh)}(hhh](h)}(h Crossmappingh]h Crossmapping}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjnhhhhhKubh)}(hThis translation algorithm is used by the kernel in quite a few places. For example, it is used when reporting back the ownership of a file to userspace via the ``stat()`` system call family.h](hThis translation algorithm is used by the kernel in quite a few places. For example, it is used when reporting back the ownership of a file to userspace via the }(hjhhhNhNubj )}(h ``stat()``h]hstat()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh system call family.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(hIf we've been given ``k11000`` from one idmapping we can map that id up in another idmapping. In order for this to work both idmappings need to contain the same kernel id in their kernel idmapsets. For example, consider the following idmappings::h](hIf we’ve been given }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh from one idmapping we can map that id up in another idmapping. In order for this to work both idmappings need to contain the same kernel id in their kernel idmapsets. For example, consider the following idmappings:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(h+1. u0:k10000:r10000 2. u20000:k10000:r10000h]h+1. u0:k10000:r10000 2. u20000:k10000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjnhhubh)}(hand we are mapping ``u1000`` down to ``k11000`` in the first idmapping . We can then translate ``k11000`` into a userspace id in the second idmapping using the kernel idmapset of the second idmapping::h](hand we are mapping }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh down to }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh0 in the first idmapping . We can then translate }(hjhhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh_ into a userspace id in the second idmapping using the kernel idmapset of the second idmapping:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(hx/* Map the kernel id up into a userspace id in the second idmapping. */ from_kuid(u20000:k10000:r10000, k11000) = u21000h]hx/* Map the kernel id up into a userspace id in the second idmapping. */ from_kuid(u20000:k10000:r10000, k11000) = u21000}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjnhhubh)}(h^Note, how we can get back to the kernel id in the first idmapping by inverting the algorithm::h]h]Note, how we can get back to the kernel id in the first idmapping by inverting the algorithm:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(h/* Map the userspace id down into a kernel id in the second idmapping. */ make_kuid(u20000:k10000:r10000, u21000) = k11000 /* Map the kernel id up into a userspace id in the first idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000h]h/* Map the userspace id down into a kernel id in the second idmapping. */ make_kuid(u20000:k10000:r10000, u21000) = k11000 /* Map the kernel id up into a userspace id in the first idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000}hj- sbah}(h]h ]h"]h$]h&]hhuh1hhhhKhjnhhubh)}(hThis algorithm allows us to answer the question what userspace id a given kernel id corresponds to in a given idmapping. In order to be able to answer this question both idmappings need to contain the same kernel id in their respective kernel idmapsets.h]hThis algorithm allows us to answer the question what userspace id a given kernel id corresponds to in a given idmapping. In order to be able to answer this question both idmappings need to contain the same kernel id in their respective kernel idmapsets.}(hj; hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(hXFor example, when the kernel reads a raw userspace id from disk it maps it down into a kernel id according to the idmapping associated with the filesystem. Let's assume the filesystem was mounted with an idmapping of ``u0:k20000:r10000`` and it reads a file owned by ``u1000`` from disk. This means ``u1000`` will be mapped to ``k21000`` which is what will be stored in the inode's ``i_uid`` and ``i_gid`` field.h](hFor example, when the kernel reads a raw userspace id from disk it maps it down into a kernel id according to the idmapping associated with the filesystem. Let’s assume the filesystem was mounted with an idmapping of }(hjI hhhNhNubj )}(h``u0:k20000:r10000``h]hu0:k20000:r10000}(hjQ hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjI ubh and it reads a file owned by }(hjI hhhNhNubj )}(h ``u1000``h]hu1000}(hjc hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjI ubh from disk. This means }(hjI hhhNhNubj )}(h ``u1000``h]hu1000}(hju hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjI ubh will be mapped to }(hjI hhhNhNubj )}(h ``k21000``h]hk21000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjI ubh/ which is what will be stored in the inode’s }(hjI hhhNhNubj )}(h ``i_uid``h]hi_uid}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjI ubh and }(hjI hhhNhNubj )}(h ``i_gid``h]hi_gid}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjI ubh field.}(hjI hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(hXWhen someone in userspace calls ``stat()`` or a related function to get ownership information about the file the kernel can't simply map the id back up according to the filesystem's idmapping as this would give the wrong owner if the caller is using an idmapping.h](h When someone in userspace calls }(hj hhhNhNubj )}(h ``stat()``h]hstat()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh or a related function to get ownership information about the file the kernel can’t simply map the id back up according to the filesystem’s idmapping as this would give the wrong owner if the caller is using an idmapping.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(hXSo the kernel will map the id back up in the idmapping of the caller. Let's assume the caller has the somewhat unconventional idmapping ``u3000:k20000:r10000`` then ``k21000`` would map back up to ``u4000``. Consequently the user would see that this file is owned by ``u4000``.h](hSo the kernel will map the id back up in the idmapping of the caller. Let’s assume the caller has the somewhat unconventional idmapping }(hj hhhNhNubj )}(h``u3000:k20000:r10000``h]hu3000:k20000:r10000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh then }(hj hhhNhNubj )}(h ``k21000``h]hk21000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh would map back up to }(hj hhhNhNubj )}(h ``u4000``h]hu4000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh=. Consequently the user would see that this file is owned by }(hj hhhNhNubj )}(h ``u4000``h]hu4000}(hj! hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubeh}(h] crossmappingah ]h"] crossmappingah$]h&]uh1hhjOhhhhhKubh)}(hhh](h)}(h Remappingh]h Remapping}(hjD hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjA hhhhhKubh)}(hIt is possible to translate a kernel id from one idmapping to another one via the userspace idmapset of the two idmappings. This is equivalent to remapping a kernel id.h]hIt is possible to translate a kernel id from one idmapping to another one via the userspace idmapset of the two idmappings. This is equivalent to remapping a kernel id.}(hjR hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjA hhubh)}(hELet's look at an example. We are given the following two idmappings::h]hFLet’s look at an example. We are given the following two idmappings:}(hj` hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjA hhubh)}(h'1. u0:k10000:r10000 2. u0:k20000:r10000h]h'1. u0:k10000:r10000 2. u0:k20000:r10000}hjn sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjA hhubh)}(hand we are given ``k11000`` in the first idmapping. In order to translate this kernel id in the first idmapping into a kernel id in the second idmapping we need to perform two steps:h](hand we are given }(hj| hhhNhNubj )}(h ``k11000``h]hk11000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj| ubh in the first idmapping. In order to translate this kernel id in the first idmapping into a kernel id in the second idmapping we need to perform two steps:}(hj| hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjA hhubhenumerated_list)}(hhh](j,)}(hMap the kernel id up into a userspace id in the first idmapping:: /* Map the kernel id up into a userspace id in the first idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000 h](h)}(hAMap the kernel id up into a userspace id in the first idmapping::h]h@Map the kernel id up into a userspace id in the first idmapping:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj ubh)}(hr/* Map the kernel id up into a userspace id in the first idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000h]hr/* Map the kernel id up into a userspace id in the first idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhM hj ubeh}(h]h ]h"]h$]h&]uh1j+hj hhhhhNubj,)}(hMap the userspace id down into a kernel id in the second idmapping:: /* Map the userspace id down into a kernel id in the second idmapping. */ make_kuid(u0:k20000:r10000, u1000) = k21000 h](h)}(hDMap the userspace id down into a kernel id in the second idmapping::h]hCMap the userspace id down into a kernel id in the second idmapping:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(hu/* Map the userspace id down into a kernel id in the second idmapping. */ make_kuid(u0:k20000:r10000, u1000) = k21000h]hu/* Map the userspace id down into a kernel id in the second idmapping. */ make_kuid(u0:k20000:r10000, u1000) = k21000}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj ubeh}(h]h ]h"]h$]h&]uh1j+hj hhhhhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1j hjA hhhhhM ubh)}(hAs you can see we used the userspace idmapset in both idmappings to translate the kernel id in one idmapping to a kernel id in another idmapping.h]hAs you can see we used the userspace idmapset in both idmappings to translate the kernel id in one idmapping to a kernel id in another idmapping.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjA hhubh)}(hXThis allows us to answer the question what kernel id we would need to use to get the same userspace id in another idmapping. In order to be able to answer this question both idmappings need to contain the same userspace id in their respective userspace idmapsets.h]hXThis allows us to answer the question what kernel id we would need to use to get the same userspace id in another idmapping. In order to be able to answer this question both idmappings need to contain the same userspace id in their respective userspace idmapsets.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjA hhubh)}(hdNote, how we can easily get back to the kernel id in the first idmapping by inverting the algorithm:h]hdNote, how we can easily get back to the kernel id in the first idmapping by inverting the algorithm:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjA hhubj )}(hhh](j,)}(hMap the kernel id up into a userspace id in the second idmapping:: /* Map the kernel id up into a userspace id in the second idmapping. */ from_kuid(u0:k20000:r10000, k21000) = u1000 h](h)}(hBMap the kernel id up into a userspace id in the second idmapping::h]hAMap the kernel id up into a userspace id in the second idmapping:}(hj) hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj% ubh)}(hs/* Map the kernel id up into a userspace id in the second idmapping. */ from_kuid(u0:k20000:r10000, k21000) = u1000h]hs/* Map the kernel id up into a userspace id in the second idmapping. */ from_kuid(u0:k20000:r10000, k21000) = u1000}hj7 sbah}(h]h ]h"]h$]h&]hhuh1hhhhM hj% ubeh}(h]h ]h"]h$]h&]uh1j+hj" hhhhhNubj,)}(hMap the userspace id down into a kernel id in the first idmapping:: /* Map the userspace id down into a kernel id in the first idmapping. */ make_kuid(u0:k10000:r10000, u1000) = k11000 h](h)}(hCMap the userspace id down into a kernel id in the first idmapping::h]hBMap the userspace id down into a kernel id in the first idmapping:}(hjO hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM#hjK ubh)}(ht/* Map the userspace id down into a kernel id in the first idmapping. */ make_kuid(u0:k10000:r10000, u1000) = k11000h]ht/* Map the userspace id down into a kernel id in the first idmapping. */ make_kuid(u0:k10000:r10000, u1000) = k11000}hj] sbah}(h]h ]h"]h$]h&]hhuh1hhhhM%hjK ubeh}(h]h ]h"]h$]h&]uh1j+hj" hhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hjA hhhhhMubh)}(hAnother way to look at this translation is to treat it as inverting one idmapping and applying another idmapping if both idmappings have the relevant userspace id mapped. This will come in handy when working with idmapped mounts.h]hAnother way to look at this translation is to treat it as inverting one idmapping and applying another idmapping if both idmappings have the relevant userspace id mapped. This will come in handy when working with idmapped mounts.}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM(hjA hhubeh}(h] remappingah ]h"] remappingah$]h&]uh1hhjOhhhhhKubh)}(hhh](h)}(hInvalid translationsh]hInvalid translations}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhM-ubh)}(hX9It is never valid to use an id in the kernel idmapset of one idmapping as the id in the userspace idmapset of another or the same idmapping. While the kernel idmapset always indicates an idmapset in the kernel id space the userspace idmapset indicates a userspace id. So the following translations are forbidden::h]hX8It is never valid to use an id in the kernel idmapset of one idmapping as the id in the userspace idmapset of another or the same idmapping. While the kernel idmapset always indicates an idmapset in the kernel id space the userspace idmapset indicates a userspace id. So the following translations are forbidden:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM/hj hhubh)}(hX/* Map the userspace id down into a kernel id in the first idmapping. */ make_kuid(u0:k10000:r10000, u1000) = k11000 /* INVALID: Map the kernel id down into a kernel id in the second idmapping. */ make_kuid(u10000:k20000:r10000, k110000) = k21000 ~~~~~~~h]hX/* Map the userspace id down into a kernel id in the first idmapping. */ make_kuid(u0:k10000:r10000, u1000) = k11000 /* INVALID: Map the kernel id down into a kernel id in the second idmapping. */ make_kuid(u10000:k20000:r10000, k110000) = k21000 ~~~~~~~}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhM4hj hhubh)}(hand equally wrong::h]hand equally wrong:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hj hhubh)}(hX/* Map the kernel id up into a userspace id in the first idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000 /* INVALID: Map the userspace id up into a userspace id in the second idmapping. */ from_kuid(u20000:k0:r10000, u1000) = k21000 ~~~~~h]hX/* Map the kernel id up into a userspace id in the first idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000 /* INVALID: Map the userspace id up into a userspace id in the second idmapping. */ from_kuid(u20000:k0:r10000, u1000) = k21000 ~~~~~}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhM=hj hhubh)}(hSince userspace ids have type ``uid_t`` and ``gid_t`` and kernel ids have type ``kuid_t`` and ``kgid_t`` the compiler will throw an error when they are conflated. So the two examples above would cause a compilation failure.h](hSince userspace ids have type }(hj hhhNhNubj )}(h ``uid_t``h]huid_t}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and }(hj hhhNhNubj )}(h ``gid_t``h]hgid_t}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and kernel ids have type }(hj hhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and }hj sbj )}(h ``kgid_t``h]hkgid_t}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhw the compiler will throw an error when they are conflated. So the two examples above would cause a compilation failure.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMDhj hhubeh}(h]invalid-translationsah ]h"]invalid translationsah$]h&]uh1hhjOhhhhhM-ubeh}(h]translation-algorithmsah ]h"]translation algorithmsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h+Idmappings when creating filesystem objectsh]h+Idmappings when creating filesystem objects}(hj? hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj< hhhhhMIubh)}(hThe concepts of mapping an id down or mapping an id up are expressed in the two kernel functions filesystem developers are rather familiar with and which we've already used in this document::h]hThe concepts of mapping an id down or mapping an id up are expressed in the two kernel functions filesystem developers are rather familiar with and which we’ve already used in this document:}(hjM hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMKhj< hhubh)}(h/* Map the userspace id down into a kernel id. */ make_kuid(idmapping, uid) /* Map the kernel id up into a userspace id. */ from_kuid(idmapping, kuid)h]h/* Map the userspace id down into a kernel id. */ make_kuid(idmapping, uid) /* Map the kernel id up into a userspace id. */ from_kuid(idmapping, kuid)}hj[ sbah}(h]h ]h"]h$]h&]hhuh1hhhhMOhj< hhubh)}(hXWe will take an abbreviated look into how idmappings figure into creating filesystem objects. For simplicity we will only look at what happens when the VFS has already completed path lookup right before it calls into the filesystem itself. So we're concerned with what happens when e.g. ``vfs_mkdir()`` is called. We will also assume that the directory we're creating filesystem objects in is readable and writable for everyone.h](hX!We will take an abbreviated look into how idmappings figure into creating filesystem objects. For simplicity we will only look at what happens when the VFS has already completed path lookup right before it calls into the filesystem itself. So we’re concerned with what happens when e.g. }(hji hhhNhNubj )}(h``vfs_mkdir()``h]h vfs_mkdir()}(hjq hhhNhNubah}(h]h ]h"]h$]h&]uh1j hji ubh is called. We will also assume that the directory we’re creating filesystem objects in is readable and writable for everyone.}(hji hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMUhj< hhubh)}(hXWhen creating a filesystem object the caller will look at the caller's filesystem ids. These are just regular ``uid_t`` and ``gid_t`` userspace ids but they are exclusively used when determining file ownership which is why they are called "filesystem ids". They are usually identical to the uid and gid of the caller but can differ. We will just assume they are always identical to not get lost in too many details.h](hpWhen creating a filesystem object the caller will look at the caller’s filesystem ids. These are just regular }(hj hhhNhNubj )}(h ``uid_t``h]huid_t}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and }(hj hhhNhNubj )}(h ``gid_t``h]hgid_t}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhX userspace ids but they are exclusively used when determining file ownership which is why they are called “filesystem ids”. They are usually identical to the uid and gid of the caller but can differ. We will just assume they are always identical to not get lost in too many details.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM\hj< hhubh)}(h4When the caller enters the kernel two things happen:h]h4When the caller enters the kernel two things happen:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMchj< hhubj )}(hhh](j,)}(hXMap the caller's userspace ids down into kernel ids in the caller's idmapping. (To be precise, the kernel will simply look at the kernel ids stashed in the credentials of the current task but for our education we'll pretend this translation happens just in time.)h]h)}(hXMap the caller's userspace ids down into kernel ids in the caller's idmapping. (To be precise, the kernel will simply look at the kernel ids stashed in the credentials of the current task but for our education we'll pretend this translation happens just in time.)h]hX Map the caller’s userspace ids down into kernel ids in the caller’s idmapping. (To be precise, the kernel will simply look at the kernel ids stashed in the credentials of the current task but for our education we’ll pretend this translation happens just in time.)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMehj ubah}(h]h ]h"]h$]h&]uh1j+hj hhhhhNubj,)}(heVerify that the caller's kernel ids can be mapped up to userspace ids in the filesystem's idmapping. h]h)}(hdVerify that the caller's kernel ids can be mapped up to userspace ids in the filesystem's idmapping.h]hhVerify that the caller’s kernel ids can be mapped up to userspace ids in the filesystem’s idmapping.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMjhj ubah}(h]h ]h"]h$]h&]uh1j+hj hhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hj< hhhhhMeubh)}(hXWThe second step is important as regular filesystem will ultimately need to map the kernel id back up into a userspace id when writing to disk. So with the second step the kernel guarantees that a valid userspace id can be written to disk. If it can't the kernel will refuse the creation request to not even remotely risk filesystem corruption.h]hXYThe second step is important as regular filesystem will ultimately need to map the kernel id back up into a userspace id when writing to disk. So with the second step the kernel guarantees that a valid userspace id can be written to disk. If it can’t the kernel will refuse the creation request to not even remotely risk filesystem corruption.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMmhj< hhubh)}(hX@The astute reader will have realized that this is simply a variation of the crossmapping algorithm we mentioned above in a previous section. First, the kernel maps the caller's userspace id down into a kernel id according to the caller's idmapping and then maps that kernel id up according to the filesystem's idmapping.h]hXFThe astute reader will have realized that this is simply a variation of the crossmapping algorithm we mentioned above in a previous section. First, the kernel maps the caller’s userspace id down into a kernel id according to the caller’s idmapping and then maps that kernel id up according to the filesystem’s idmapping.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMshj< hhubh)}(hFrom the implementation point it's worth mentioning how idmappings are represented. All idmappings are taken from the corresponding user namespace.h]hFrom the implementation point it’s worth mentioning how idmappings are represented. All idmappings are taken from the corresponding user namespace.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMyhj< hhubh block_quote)}(h- caller's idmapping (usually taken from ``current_user_ns()``) - filesystem's idmapping (``sb->s_user_ns``) - mount's idmapping (``mnt_idmap(vfsmnt)``) h]j')}(hhh](j,)}(h=caller's idmapping (usually taken from ``current_user_ns()``)h]h)}(hj7 h](h)caller’s idmapping (usually taken from }(hj9 hhhNhNubj )}(h``current_user_ns()``h]hcurrent_user_ns()}(hj@ hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj9 ubh)}(hj9 hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM|hj5 ubah}(h]h ]h"]h$]h&]uh1j+hj2 ubj,)}(h*filesystem's idmapping (``sb->s_user_ns``)h]h)}(hj` h](hfilesystem’s idmapping (}(hjb hhhNhNubj )}(h``sb->s_user_ns``h]h sb->s_user_ns}(hji hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjb ubh)}(hjb hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM}hj^ ubah}(h]h ]h"]h$]h&]uh1j+hj2 ubj,)}(h*mount's idmapping (``mnt_idmap(vfsmnt)``) h]h)}(h)mount's idmapping (``mnt_idmap(vfsmnt)``)h](hmount’s idmapping (}(hj hhhNhNubj )}(h``mnt_idmap(vfsmnt)``h]hmnt_idmap(vfsmnt)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh)}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM~hj ubah}(h]h ]h"]h$]h&]uh1j+hj2 ubeh}(h]h ]h"]h$]h&]jjuh1j&hhhM|hj. ubah}(h]h ]h"]h$]h&]uh1j, hhhM|hj< hhubh)}(hXLet's see some examples with caller/filesystem idmapping but without mount idmappings. This will exhibit some problems we can hit. After that we will revisit/reconsider these examples, this time using mount idmappings, to see how they can solve the problems we observed before.h]hXLet’s see some examples with caller/filesystem idmapping but without mount idmappings. This will exhibit some problems we can hit. After that we will revisit/reconsider these examples, this time using mount idmappings, to see how they can solve the problems we observed before.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj< hhubh)}(hhh](h)}(h Example 1h]h Example 1}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(hkcaller id: u1000 caller idmapping: u0:k0:r4294967295 filesystem idmapping: u0:k0:r4294967295h]hkcaller id: u1000 caller idmapping: u0:k0:r4294967295 filesystem idmapping: u0:k0:r4294967295}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj hhubh)}(h>Both the caller and the filesystem use the identity idmapping:h]h>Both the caller and the filesystem use the identity idmapping:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj )}(hhh](j,)}(hyMap the caller's userspace ids into kernel ids in the caller's idmapping:: make_kuid(u0:k0:r4294967295, u1000) = k1000 h](h)}(hJMap the caller's userspace ids into kernel ids in the caller's idmapping::h]hMMap the caller’s userspace ids into kernel ids in the caller’s idmapping:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(h+make_kuid(u0:k0:r4294967295, u1000) = k1000h]h+make_kuid(u0:k0:r4294967295, u1000) = k1000}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj ubeh}(h]h ]h"]h$]h&]uh1j+hj hhhhhNubj,)}(hXVerify that the caller's kernel ids can be mapped to userspace ids in the filesystem's idmapping. For this second step the kernel will call the function ``fsuidgid_has_mapping()`` which ultimately boils down to calling ``from_kuid()``:: from_kuid(u0:k0:r4294967295, k1000) = u1000 h](h)}(haVerify that the caller's kernel ids can be mapped to userspace ids in the filesystem's idmapping.h]heVerify that the caller’s kernel ids can be mapped to userspace ids in the filesystem’s idmapping.}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj!ubh)}(hFor this second step the kernel will call the function ``fsuidgid_has_mapping()`` which ultimately boils down to calling ``from_kuid()``::h](h7For this second step the kernel will call the function }(hj3hhhNhNubj )}(h``fsuidgid_has_mapping()``h]hfsuidgid_has_mapping()}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj3ubh( which ultimately boils down to calling }(hj3hhhNhNubj )}(h``from_kuid()``h]h from_kuid()}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj3ubh:}(hj3hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj!ubh)}(h+from_kuid(u0:k0:r4294967295, k1000) = u1000h]h+from_kuid(u0:k0:r4294967295, k1000) = u1000}hjesbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj!ubeh}(h]h ]h"]h$]h&]uh1j+hj hhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hj hhhhhMubh)}(hIn this example both idmappings are the same so there's nothing exciting going on. Ultimately the userspace id that lands on disk will be ``u1000``.h](hIn this example both idmappings are the same so there’s nothing exciting going on. Ultimately the userspace id that lands on disk will be }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubeh}(h] example-1ah ]h"] example 1ah$]h&]uh1hhj< hhhhhMubh)}(hhh](h)}(h Example 2h]h Example 2}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hicaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000h]hicaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubj )}(hhh](j,)}(h~Map the caller's userspace ids down into kernel ids in the caller's idmapping:: make_kuid(u0:k10000:r10000, u1000) = k11000 h](h)}(hOMap the caller's userspace ids down into kernel ids in the caller's idmapping::h]hRMap the caller’s userspace ids down into kernel ids in the caller’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h+make_kuid(u0:k10000:r10000, u1000) = k11000h]h+make_kuid(u0:k10000:r10000, u1000) = k11000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(hVerify that the caller's kernel ids can be mapped up to userspace ids in the filesystem's idmapping:: from_kuid(u0:k20000:r10000, k11000) = u-1 h](h)}(heVerify that the caller's kernel ids can be mapped up to userspace ids in the filesystem's idmapping::h]hhVerify that the caller’s kernel ids can be mapped up to userspace ids in the filesystem’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h)from_kuid(u0:k20000:r10000, k11000) = u-1h]h)from_kuid(u0:k20000:r10000, k11000) = u-1}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hjhhhhhMubh)}(hXIt's immediately clear that while the caller's userspace id could be successfully mapped down into kernel ids in the caller's idmapping the kernel ids could not be mapped up according to the filesystem's idmapping. So the kernel will deny this creation request.h]hX It’s immediately clear that while the caller’s userspace id could be successfully mapped down into kernel ids in the caller’s idmapping the kernel ids could not be mapped up according to the filesystem’s idmapping. So the kernel will deny this creation request.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhh Mhjhhubh)}(hNote that while this example is less common, because most filesystem can't be mounted with non-initial idmappings this is a general problem as we can see in the next examples.h]hNote that while this example is less common, because most filesystem can’t be mounted with non-initial idmappings this is a general problem as we can see in the next examples.}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h] example-2ah ]h"] example 2ah$]h&]uh1hhj< hhhhhMubh)}(hhh](h)}(h Example 3h]h Example 3}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj?hhhhhMubh)}(hjcaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k0:r4294967295h]hjcaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k0:r4294967295}hjPsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj?hhubj )}(hhh](j,)}(h~Map the caller's userspace ids down into kernel ids in the caller's idmapping:: make_kuid(u0:k10000:r10000, u1000) = k11000 h](h)}(hOMap the caller's userspace ids down into kernel ids in the caller's idmapping::h]hRMap the caller’s userspace ids down into kernel ids in the caller’s idmapping:}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjaubh)}(h+make_kuid(u0:k10000:r10000, u1000) = k11000h]h+make_kuid(u0:k10000:r10000, u1000) = k11000}hjssbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjaubeh}(h]h ]h"]h$]h&]uh1j+hj^hhhhhNubj,)}(hVerify that the caller's kernel ids can be mapped up to userspace ids in the filesystem's idmapping:: from_kuid(u0:k0:r4294967295, k11000) = u11000 h](h)}(heVerify that the caller's kernel ids can be mapped up to userspace ids in the filesystem's idmapping::h]hhVerify that the caller’s kernel ids can be mapped up to userspace ids in the filesystem’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h-from_kuid(u0:k0:r4294967295, k11000) = u11000h]h-from_kuid(u0:k0:r4294967295, k11000) = u11000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hj^hhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hj?hhhhhMubh)}(hWe can see that the translation always succeeds. The userspace id that the filesystem will ultimately put to disk will always be identical to the value of the kernel id that was created in the caller's idmapping. This has mainly two consequences.h]hWe can see that the translation always succeeds. The userspace id that the filesystem will ultimately put to disk will always be identical to the value of the kernel id that was created in the caller’s idmapping. This has mainly two consequences.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj?hhubh)}(hXVFirst, that we can't allow a caller to ultimately write to disk with another userspace id. We could only do this if we were to mount the whole filesystem with the caller's or another idmapping. But that solution is limited to a few filesystems and not very flexible. But this is a use-case that is pretty important in containerized workloads.h]hXZFirst, that we can’t allow a caller to ultimately write to disk with another userspace id. We could only do this if we were to mount the whole filesystem with the caller’s or another idmapping. But that solution is limited to a few filesystems and not very flexible. But this is a use-case that is pretty important in containerized workloads.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj?hhubh)}(hSecond, the caller will usually not be able to create any files or access directories that have stricter permissions because none of the filesystem's kernel ids map up into valid userspace ids in the caller's idmappingh]hSecond, the caller will usually not be able to create any files or access directories that have stricter permissions because none of the filesystem’s kernel ids map up into valid userspace ids in the caller’s idmapping}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj?hhubj )}(hhh](j,)}(hwMap raw userspace ids down to kernel ids in the filesystem's idmapping:: make_kuid(u0:k0:r4294967295, u1000) = k1000 h](h)}(hHMap raw userspace ids down to kernel ids in the filesystem's idmapping::h]hIMap raw userspace ids down to kernel ids in the filesystem’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h+make_kuid(u0:k0:r4294967295, u1000) = k1000h]h+make_kuid(u0:k0:r4294967295, u1000) = k1000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(hjMap kernel ids up to userspace ids in the caller's idmapping:: from_kuid(u0:k10000:r10000, k1000) = u-1 h](h)}(h>Map kernel ids up to userspace ids in the caller's idmapping::h]h?Map kernel ids up to userspace ids in the caller’s idmapping:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h(from_kuid(u0:k10000:r10000, k1000) = u-1h]h(from_kuid(u0:k10000:r10000, k1000) = u-1}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hj?hhhhhMubeh}(h] example-3ah ]h"] example 3ah$]h&]uh1hhj< hhhhhMubh)}(hhh](h)}(h Example 4h]h Example 4}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj:hhhhhMubh)}(hjfile id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k0:r4294967295h]hjfile id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k0:r4294967295}hjKsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj:hhubh)}(hvIn order to report ownership to userspace the kernel uses the crossmapping algorithm introduced in a previous section:h]hvIn order to report ownership to userspace the kernel uses the crossmapping algorithm introduced in a previous section:}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj:hhubj )}(hhh](j,)}(hMap the userspace id on disk down into a kernel id in the filesystem's idmapping:: make_kuid(u0:k0:r4294967295, u1000) = k1000 h](h)}(hRMap the userspace id on disk down into a kernel id in the filesystem's idmapping::h]hSMap the userspace id on disk down into a kernel id in the filesystem’s idmapping:}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjjubh)}(h+make_kuid(u0:k0:r4294967295, u1000) = k1000h]h+make_kuid(u0:k0:r4294967295, u1000) = k1000}hj|sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjjubeh}(h]h ]h"]h$]h&]uh1j+hjghhhhhNubj,)}(hpMap the kernel id up into a userspace id in the caller's idmapping:: from_kuid(u0:k10000:r10000, k1000) = u-1 h](h)}(hDMap the kernel id up into a userspace id in the caller's idmapping::h]hEMap the kernel id up into a userspace id in the caller’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h(from_kuid(u0:k10000:r10000, k1000) = u-1h]h(from_kuid(u0:k10000:r10000, k1000) = u-1}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjghhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hj:hhhhhMubh)}(hThe crossmapping algorithm fails in this case because the kernel id in the filesystem idmapping cannot be mapped up to a userspace id in the caller's idmapping. Thus, the kernel will report the ownership of this file as the overflowid.h]hThe crossmapping algorithm fails in this case because the kernel id in the filesystem idmapping cannot be mapped up to a userspace id in the caller’s idmapping. Thus, the kernel will report the ownership of this file as the overflowid.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj:hhubeh}(h] example-4ah ]h"] example 4ah$]h&]uh1hhj< hhhhhMubh)}(hhh](h)}(h Example 5h]h Example 5}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hifile id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000h]hifile id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hvIn order to report ownership to userspace the kernel uses the crossmapping algorithm introduced in a previous section:h]hvIn order to report ownership to userspace the kernel uses the crossmapping algorithm introduced in a previous section:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjhhubj )}(hhh](j,)}(hMap the userspace id on disk down into a kernel id in the filesystem's idmapping:: make_kuid(u0:k20000:r10000, u1000) = k21000 h](h)}(hRMap the userspace id on disk down into a kernel id in the filesystem's idmapping::h]hSMap the userspace id on disk down into a kernel id in the filesystem’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjubh)}(h+make_kuid(u0:k20000:r10000, u1000) = k21000h]h+make_kuid(u0:k20000:r10000, u1000) = k21000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(hqMap the kernel id up into a userspace id in the caller's idmapping:: from_kuid(u0:k10000:r10000, k21000) = u-1 h](h)}(hDMap the kernel id up into a userspace id in the caller's idmapping::h]hEMap the kernel id up into a userspace id in the caller’s idmapping:}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj(ubh)}(h)from_kuid(u0:k10000:r10000, k21000) = u-1h]h)from_kuid(u0:k10000:r10000, k21000) = u-1}hj:sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj(ubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hjhhhhhM ubh)}(hAgain, the crossmapping algorithm fails in this case because the kernel id in the filesystem idmapping cannot be mapped to a userspace id in the caller's idmapping. Thus, the kernel will report the ownership of this file as the overflowid.h]hAgain, the crossmapping algorithm fails in this case because the kernel id in the filesystem idmapping cannot be mapped to a userspace id in the caller’s idmapping. Thus, the kernel will report the ownership of this file as the overflowid.}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXNote how in the last two examples things would be simple if the caller would be using the initial idmapping. For a filesystem mounted with the initial idmapping it would be trivial. So we only consider a filesystem with an idmapping of ``u0:k20000:r10000``:h](hNote how in the last two examples things would be simple if the caller would be using the initial idmapping. For a filesystem mounted with the initial idmapping it would be trivial. So we only consider a filesystem with an idmapping of }(hjbhhhNhNubj )}(h``u0:k20000:r10000``h]hu0:k20000:r10000}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjbubh:}(hjbhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(hhh](j,)}(hMap the userspace id on disk down into a kernel id in the filesystem's idmapping:: make_kuid(u0:k20000:r10000, u1000) = k21000 h](h)}(hRMap the userspace id on disk down into a kernel id in the filesystem's idmapping::h]hSMap the userspace id on disk down into a kernel id in the filesystem’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h+make_kuid(u0:k20000:r10000, u1000) = k21000h]h+make_kuid(u0:k20000:r10000, u1000) = k21000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhM"hjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(huMap the kernel id up into a userspace id in the caller's idmapping:: from_kuid(u0:k0:r4294967295, k21000) = u21000 h](h)}(hDMap the kernel id up into a userspace id in the caller's idmapping::h]hEMap the kernel id up into a userspace id in the caller’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM$hjubh)}(h-from_kuid(u0:k0:r4294967295, k21000) = u21000h]h-from_kuid(u0:k0:r4294967295, k21000) = u21000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhM&hjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hjhhhhhMubeh}(h] example-5ah ]h"] example 5ah$]h&]uh1hhj< hhhhhMubeh}(h]+idmappings-when-creating-filesystem-objectsah ]h"]+idmappings when creating filesystem objectsah$]h&]uh1hhhhhhhhMIubh)}(hhh](h)}(hIdmappings on idmapped mountsh]hIdmappings on idmapped mounts}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM)ubh)}(hXThe examples we've seen in the previous section where the caller's idmapping and the filesystem's idmapping are incompatible causes various issues for workloads. For a more complex but common example, consider two containers started on the host. To completely prevent the two containers from affecting each other, an administrator may often use different non-overlapping idmappings for the two containers::h]hXThe examples we’ve seen in the previous section where the caller’s idmapping and the filesystem’s idmapping are incompatible causes various issues for workloads. For a more complex but common example, consider two containers started on the host. To completely prevent the two containers from affecting each other, an administrator may often use different non-overlapping idmappings for the two containers:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM+hjhhubh)}(hwcontainer1 idmapping: u0:k10000:r10000 container2 idmapping: u0:k20000:r10000 filesystem idmapping: u0:k30000:r10000h]hwcontainer1 idmapping: u0:k10000:r10000 container2 idmapping: u0:k20000:r10000 filesystem idmapping: u0:k30000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhM2hjhhubh)}(hZAn administrator wanting to provide easy read-write access to the following set of files::h]hYAn administrator wanting to provide easy read-write access to the following set of files:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM6hjhhubh)}(h8dir id: u0 dir/file1 id: u1000 dir/file2 id: u2000h]h8dir id: u0 dir/file1 id: u1000 dir/file2 id: u2000}hj"sbah}(h]h ]h"]h$]h&]hhuh1hhhhM9hjhhubh)}(h#to both containers currently can't.h]h%to both containers currently can’t.}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM=hjhhubh)}(hXROf course the administrator has the option to recursively change ownership via ``chown()``. For example, they could change ownership so that ``dir`` and all files below it can be crossmapped from the filesystem's into the container's idmapping. Let's assume they change ownership so it is compatible with the first container's idmapping::h](hOOf course the administrator has the option to recursively change ownership via }(hj>hhhNhNubj )}(h ``chown()``h]hchown()}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj>ubh3. For example, they could change ownership so that }(hj>hhhNhNubj )}(h``dir``h]hdir}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj>ubh and all files below it can be crossmapped from the filesystem’s into the container’s idmapping. Let’s assume they change ownership so it is compatible with the first container’s idmapping:}(hj>hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM?hjhhubh)}(h>dir id: u10000 dir/file1 id: u11000 dir/file2 id: u12000h]h>dir id: u10000 dir/file1 id: u11000 dir/file2 id: u12000}hjpsbah}(h]h ]h"]h$]h&]hhuh1hhhhMEhjhhubh)}(hThis would still leave ``dir`` rather useless to the second container. In fact, ``dir`` and all files below it would continue to appear owned by the overflowid for the second container.h](hThis would still leave }(hj~hhhNhNubj )}(h``dir``h]hdir}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj~ubh2 rather useless to the second container. In fact, }(hj~hhhNhNubj )}(h``dir``h]hdir}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj~ubhb and all files below it would continue to appear owned by the overflowid for the second container.}(hj~hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMIhjhhubh)}(hX<Or consider another increasingly popular example. Some service managers such as systemd implement a concept called "portable home directories". A user may want to use their home directories on different machines where they are assigned different login userspace ids. Most users will have ``u1000`` as the login id on their machine at home and all files in their home directory will usually be owned by ``u1000``. At uni or at work they may have another login id such as ``u1125``. This makes it rather difficult to interact with their home directory on their work machine.h](hX$Or consider another increasingly popular example. Some service managers such as systemd implement a concept called “portable home directories”. A user may want to use their home directories on different machines where they are assigned different login userspace ids. Most users will have }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhi as the login id on their machine at home and all files in their home directory will usually be owned by }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh;. At uni or at work they may have another login id such as }(hjhhhNhNubj )}(h ``u1125``h]hu1125}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh]. This makes it rather difficult to interact with their home directory on their work machine.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMMhjhhubh)}(hXcIn both cases changing ownership recursively has grave implications. The most obvious one is that ownership is changed globally and permanently. In the home directory case this change in ownership would even need to happen every time the user switches from their home to their work machine. For really large sets of files this becomes increasingly costly.h]hXcIn both cases changing ownership recursively has grave implications. The most obvious one is that ownership is changed globally and permanently. In the home directory case this change in ownership would even need to happen every time the user switches from their home to their work machine. For really large sets of files this becomes increasingly costly.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMVhjhhubh)}(hX+If the user is lucky, they are dealing with a filesystem that is mountable inside user namespaces. But this would also change ownership globally and the change in ownership is tied to the lifetime of the filesystem mount, i.e. the superblock. The only way to change ownership is to completely unmount the filesystem and mount it again in another user namespace. This is usually impossible because it would mean that all users currently accessing the filesystem can't anymore. And it means that ``dir`` still can't be shared between two containers with different idmappings. But usually the user doesn't even have this option since most filesystems aren't mountable inside containers. And not having them mountable might be desirable as it doesn't require the filesystem to deal with malicious filesystem images.h](hXIf the user is lucky, they are dealing with a filesystem that is mountable inside user namespaces. But this would also change ownership globally and the change in ownership is tied to the lifetime of the filesystem mount, i.e. the superblock. The only way to change ownership is to completely unmount the filesystem and mount it again in another user namespace. This is usually impossible because it would mean that all users currently accessing the filesystem can’t anymore. And it means that }(hjhhhNhNubj )}(h``dir``h]hdir}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhX> still can’t be shared between two containers with different idmappings. But usually the user doesn’t even have this option since most filesystems aren’t mountable inside containers. And not having them mountable might be desirable as it doesn’t require the filesystem to deal with malicious filesystem images.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM\hjhhubh)}(hXBut the usecases mentioned above and more can be handled by idmapped mounts. They allow to expose the same set of dentries with different ownership at different mounts. This is achieved by marking the mounts with a user namespace through the ``mount_setattr()`` system call. The idmapping associated with it is then used to translate from the caller's idmapping to the filesystem's idmapping and vica versa using the remapping algorithm we introduced above.h](hBut the usecases mentioned above and more can be handled by idmapped mounts. They allow to expose the same set of dentries with different ownership at different mounts. This is achieved by marking the mounts with a user namespace through the }(hj"hhhNhNubj )}(h``mount_setattr()``h]hmount_setattr()}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj"ubh system call. The idmapping associated with it is then used to translate from the caller’s idmapping to the filesystem’s idmapping and vica versa using the remapping algorithm we introduced above.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMihjhhubh)}(hXIdmapped mounts make it possible to change ownership in a temporary and localized way. The ownership changes are restricted to a specific mount and the ownership changes are tied to the lifetime of the mount. All other users and locations where the filesystem is exposed are unaffected.h]hXIdmapped mounts make it possible to change ownership in a temporary and localized way. The ownership changes are restricted to a specific mount and the ownership changes are tied to the lifetime of the mount. All other users and locations where the filesystem is exposed are unaffected.}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMphjhhubh)}(hXSFilesystems that support idmapped mounts don't have any real reason to support being mountable inside user namespaces. A filesystem could be exposed completely under an idmapped mount to get the same effect. This has the advantage that filesystems can leave the creation of the superblock to privileged users in the initial user namespace.h]hXUFilesystems that support idmapped mounts don’t have any real reason to support being mountable inside user namespaces. A filesystem could be exposed completely under an idmapped mount to get the same effect. This has the advantage that filesystems can leave the creation of the superblock to privileged users in the initial user namespace.}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMuhjhhubh)}(hHowever, it is perfectly possible to combine idmapped mounts with filesystems mountable inside user namespaces. We will touch on this further below.h]hHowever, it is perfectly possible to combine idmapped mounts with filesystems mountable inside user namespaces. We will touch on this further below.}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM{hjhhubh)}(hhh](h)}(h(Filesystem types vs idmapped mount typesh]h(Filesystem types vs idmapped mount types}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1hhjlhhhhhMubh)}(hXWith the introduction of idmapped mounts we need to distinguish between filesystem ownership and mount ownership of a VFS object such as an inode. The owner of a inode might be different when looked at from a filesystem perspective than when looked at from an idmapped mount. Such fundamental conceptual distinctions should almost always be clearly expressed in the code. So, to distinguish idmapped mount ownership from filesystem ownership separate types have been introduced.h]hXWith the introduction of idmapped mounts we need to distinguish between filesystem ownership and mount ownership of a VFS object such as an inode. The owner of a inode might be different when looked at from a filesystem perspective than when looked at from an idmapped mount. Such fundamental conceptual distinctions should almost always be clearly expressed in the code. So, to distinguish idmapped mount ownership from filesystem ownership separate types have been introduced.}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hXIf a uid or gid has been generated using the filesystem or caller's idmapping then we will use the ``kuid_t`` and ``kgid_t`` types. However, if a uid or gid has been generated using a mount idmapping then we will be using the dedicated ``vfsuid_t`` and ``vfsgid_t`` types.h](heIf a uid or gid has been generated using the filesystem or caller’s idmapping then we will use the }(hjhhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``kgid_t``h]hkgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhp types. However, if a uid or gid has been generated using a mount idmapping then we will be using the dedicated }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }hjsbj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh types.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hAll VFS helpers that generate or take uids and gids as arguments use the ``vfsuid_t`` and ``vfsgid_t`` types and we will be able to rely on the compiler to catch errors that originate from conflating filesystem and VFS uids and gids.h](hIAll VFS helpers that generate or take uids and gids as arguments use the }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh types and we will be able to rely on the compiler to catch errors that originate from conflating filesystem and VFS uids and gids.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hThe ``vfsuid_t`` and ``vfsgid_t`` types are often mapped from and to ``kuid_t`` and ``kgid_t`` types similar how ``kuid_t`` and ``kgid_t`` types are mapped from and to ``uid_t`` and ``gid_t`` types::h](hThe }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh$ types are often mapped from and to }(hjhhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``kgid_t``h]hkgid_t}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh types similar how }(hjhhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }hjsbj )}(h ``kgid_t``h]hkgid_t}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh types are mapped from and to }(hjhhhNhNubj )}(h ``uid_t``h]huid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }hjsbj )}(h ``gid_t``h]hgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh types:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(h?uid_t <--> kuid_t <--> vfsuid_t gid_t <--> kgid_t <--> vfsgid_th]h?uid_t <--> kuid_t <--> vfsuid_t gid_t <--> kgid_t <--> vfsgid_t}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjlhhubh)}(hX*Whenever we report ownership based on a ``vfsuid_t`` or ``vfsgid_t`` type, e.g., during ``stat()``, or store ownership information in a shared VFS object based on a ``vfsuid_t`` or ``vfsgid_t`` type, e.g., during ``chown()`` we can use the ``vfsuid_into_kuid()`` and ``vfsgid_into_kgid()`` helpers.h](h(Whenever we report ownership based on a }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }(hjhhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh type, e.g., during }(hjhhhNhNubj )}(h ``stat()``h]hstat()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhC, or store ownership information in a shared VFS object based on a }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }hjsbj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh type, e.g., during }(hjhhhNhNubj )}(h ``chown()``h]hchown()}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh we can use the }(hjhhhNhNubj )}(h``vfsuid_into_kuid()``h]hvfsuid_into_kuid()}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``vfsgid_into_kgid()``h]hvfsgid_into_kgid()}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh helpers.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hXTo illustrate why this helper currently exists, consider what happens when we change ownership of an inode from an idmapped mount. After we generated a ``vfsuid_t`` or ``vfsgid_t`` based on the mount idmapping we later commit to this ``vfsuid_t`` or ``vfsgid_t`` to become the new filesystem wide ownership. Thus, we are turning the ``vfsuid_t`` or ``vfsgid_t`` into a global ``kuid_t`` or ``kgid_t``. And this can be done by using ``vfsuid_into_kuid()`` and ``vfsgid_into_kgid()``.h](hTo illustrate why this helper currently exists, consider what happens when we change ownership of an inode from an idmapped mount. After we generated a }(hj]hhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh or }(hj]hhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh6 based on the mount idmapping we later commit to this }(hj]hhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh or }hj]sbj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubhG to become the new filesystem wide ownership. Thus, we are turning the }(hj]hhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh or }hj]sbj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh into a global }(hj]hhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh or }(hj]hhhNhNubj )}(h ``kgid_t``h]hkgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh . And this can be done by using }(hj]hhhNhNubj )}(h``vfsuid_into_kuid()``h]hvfsuid_into_kuid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh and }(hj]hhhNhNubj )}(h``vfsgid_into_kgid()``h]hvfsgid_into_kgid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]ubh.}(hj]hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hXNote, whenever a shared VFS object, e.g., a cached ``struct inode`` or a cached ``struct posix_acl``, stores ownership information a filesystem or "global" ``kuid_t`` and ``kgid_t`` must be used. Ownership expressed via ``vfsuid_t`` and ``vfsgid_t`` is specific to an idmapped mount.h](h3Note, whenever a shared VFS object, e.g., a cached }(hjhhhNhNubj )}(h``struct inode``h]h struct inode}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or a cached }(hjhhhNhNubj )}(h``struct posix_acl``h]hstruct posix_acl}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh<, stores ownership information a filesystem or “global” }(hjhhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``kgid_t``h]hkgid_t}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh' must be used. Ownership expressed via }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh" is specific to an idmapped mount.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hXWe already noted that ``vfsuid_t`` and ``vfsgid_t`` types are generated based on mount idmappings whereas ``kuid_t`` and ``kgid_t`` types are generated based on filesystem idmappings. To prevent abusing filesystem idmappings to generate ``vfsuid_t`` or ``vfsgid_t`` types or mount idmappings to generate ``kuid_t`` or ``kgid_t`` types filesystem idmappings and mount idmappings are different types as well.h](hWe already noted that }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh7 types are generated based on mount idmappings whereas }(hjhhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }hjsbj )}(h ``kgid_t``h]hkgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhj types are generated based on filesystem idmappings. To prevent abusing filesystem idmappings to generate }(hjhhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }(hjhhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh' types or mount idmappings to generate }(hjhhhNhNubj )}(h ``kuid_t``h]hkuid_t}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }(hjhhhNhNubj )}(h ``kgid_t``h]hkgid_t}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhN types filesystem idmappings and mount idmappings are different types as well.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hAll helpers that map to or from ``vfsuid_t`` and ``vfsgid_t`` types require a mount idmapping to be passed which is of type ``struct mnt_idmap``. Passing a filesystem or caller idmapping will cause a compilation error.h](h All helpers that map to or from }(hj7hhhNhNubj )}(h ``vfsuid_t``h]hvfsuid_t}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj7ubh and }(hj7hhhNhNubj )}(h ``vfsgid_t``h]hvfsgid_t}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj7ubh? types require a mount idmapping to be passed which is of type }(hj7hhhNhNubj )}(h``struct mnt_idmap``h]hstruct mnt_idmap}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1j hj7ubhJ. Passing a filesystem or caller idmapping will cause a compilation error.}(hj7hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubh)}(hSimilar to how we prefix all userspace ids in this document with ``u`` and all kernel ids with ``k`` we will prefix all VFS ids with ``v``. So a mount idmapping will be written as: ``u0:v10000:r10000``.h](hASimilar to how we prefix all userspace ids in this document with }(hj{hhhNhNubj )}(h``u``h]hu}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj{ubh and all kernel ids with }(hj{hhhNhNubj )}(h``k``h]hk}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj{ubh! we will prefix all VFS ids with }(hj{hhhNhNubj )}(h``v``h]hv}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj{ubh+. So a mount idmapping will be written as: }(hj{hhhNhNubj )}(h``u0:v10000:r10000``h]hu0:v10000:r10000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj{ubh.}(hj{hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjlhhubeh}(h](filesystem-types-vs-idmapped-mount-typesah ]h"](filesystem types vs idmapped mount typesah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hRemapping helpersh]hRemapping helpers}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hIdmapping functions were added that translate between idmappings. They make use of the remapping algorithm we've introduced earlier. We're going to look at:h]hIdmapping functions were added that translate between idmappings. They make use of the remapping algorithm we’ve introduced earlier. We’re going to look at:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj')}(hhh](j,)}(hX``i_uid_into_vfsuid()`` and ``i_gid_into_vfsgid()`` The ``i_*id_into_vfs*id()`` functions translate filesystem's kernel ids into VFS ids in the mount's idmapping:: /* Map the filesystem's kernel id up into a userspace id in the filesystem's idmapping. */ from_kuid(filesystem, kid) = uid /* Map the filesystem's userspace id down ito a VFS id in the mount's idmapping. */ make_kuid(mount, uid) = kuid h](h)}(h3``i_uid_into_vfsuid()`` and ``i_gid_into_vfsgid()``h](j )}(h``i_uid_into_vfsuid()``h]hi_uid_into_vfsuid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``i_gid_into_vfsgid()``h]hi_gid_into_vfsgid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hoThe ``i_*id_into_vfs*id()`` functions translate filesystem's kernel ids into VFS ids in the mount's idmapping::h](hThe }(hj)hhhNhNubj )}(h``i_*id_into_vfs*id()``h]hi_*id_into_vfs*id()}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj)ubhW functions translate filesystem’s kernel ids into VFS ids in the mount’s idmapping:}(hj)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(h/* Map the filesystem's kernel id up into a userspace id in the filesystem's idmapping. */ from_kuid(filesystem, kid) = uid /* Map the filesystem's userspace id down ito a VFS id in the mount's idmapping. */ make_kuid(mount, uid) = kuidh]h/* Map the filesystem's kernel id up into a userspace id in the filesystem's idmapping. */ from_kuid(filesystem, kid) = uid /* Map the filesystem's userspace id down ito a VFS id in the mount's idmapping. */ make_kuid(mount, uid) = kuid}hjIsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(hX``mapped_fsuid()`` and ``mapped_fsgid()`` The ``mapped_fs*id()`` functions translate the caller's kernel ids into kernel ids in the filesystem's idmapping. This translation is achieved by remapping the caller's VFS ids using the mount's idmapping:: /* Map the caller's VFS id up into a userspace id in the mount's idmapping. */ from_kuid(mount, kid) = uid /* Map the mount's userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(filesystem, uid) = kuid h](h)}(h)``mapped_fsuid()`` and ``mapped_fsgid()``h](j )}(h``mapped_fsuid()``h]hmapped_fsuid()}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1j hjaubh and }(hjahhhNhNubj )}(h``mapped_fsgid()``h]hmapped_fsgid()}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjaubeh}(h]h ]h"]h$]h&]uh1hhhhMhj]ubh)}(hThe ``mapped_fs*id()`` functions translate the caller's kernel ids into kernel ids in the filesystem's idmapping. This translation is achieved by remapping the caller's VFS ids using the mount's idmapping::h](hThe }(hjhhhNhNubj )}(h``mapped_fs*id()``h]hmapped_fs*id()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh functions translate the caller’s kernel ids into kernel ids in the filesystem’s idmapping. This translation is achieved by remapping the caller’s VFS ids using the mount’s idmapping:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj]ubh)}(h/* Map the caller's VFS id up into a userspace id in the mount's idmapping. */ from_kuid(mount, kid) = uid /* Map the mount's userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(filesystem, uid) = kuidh]h/* Map the caller's VFS id up into a userspace id in the mount's idmapping. */ from_kuid(mount, kid) = uid /* Map the mount's userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(filesystem, uid) = kuid}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj]ubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(h=``vfsuid_into_kuid()`` and ``vfsgid_into_kgid()`` Whenever h](h)}(h1``vfsuid_into_kuid()`` and ``vfsgid_into_kgid()``h](j )}(h``vfsuid_into_kuid()``h]hvfsuid_into_kuid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``vfsgid_into_kgid()``h]hvfsgid_into_kgid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubj- )}(h Whenever h]h)}(hWheneverh]hWhenever}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j, hhhMhjubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j&hhhMhjhhubh)}(hTNote that these two functions invert each other. Consider the following idmappings::h]hSNote that these two functions invert each other. Consider the following idmappings:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(htcaller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000 mount idmapping: u0:v10000:r10000h]htcaller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000 mount idmapping: u0:v10000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hAssume a file owned by ``u1000`` is read from disk. The filesystem maps this id to ``k21000`` according to its idmapping. This is what is stored in the inode's ``i_uid`` and ``i_gid`` fields.h](hAssume a file owned by }(hj-hhhNhNubj )}(h ``u1000``h]hu1000}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj-ubh3 is read from disk. The filesystem maps this id to }(hj-hhhNhNubj )}(h ``k21000``h]hk21000}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj-ubhE according to its idmapping. This is what is stored in the inode’s }(hj-hhhNhNubj )}(h ``i_uid``h]hi_uid}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj-ubh and }(hj-hhhNhNubj )}(h ``i_gid``h]hi_gid}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj-ubh fields.}(hj-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hWhen the caller queries the ownership of this file via ``stat()`` the kernel would usually simply use the crossmapping algorithm and map the filesystem's kernel id up to a userspace id in the caller's idmapping.h](h7When the caller queries the ownership of this file via }(hjhhhNhNubj )}(h ``stat()``h]hstat()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh the kernel would usually simply use the crossmapping algorithm and map the filesystem’s kernel id up to a userspace id in the caller’s idmapping.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hBut when the caller is accessing the file on an idmapped mount the kernel will first call ``i_uid_into_vfsuid()`` thereby translating the filesystem's kernel id into a VFS id in the mount's idmapping::h](hZBut when the caller is accessing the file on an idmapped mount the kernel will first call }(hjhhhNhNubj )}(h``i_uid_into_vfsuid()``h]hi_uid_into_vfsuid()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh[ thereby translating the filesystem’s kernel id into a VFS id in the mount’s idmapping:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX i_uid_into_vfsuid(k21000): /* Map the filesystem's kernel id up into a userspace id. */ from_kuid(u0:k20000:r10000, k21000) = u1000 /* Map the filesystem's userspace id down into a VFS id in the mount's idmapping. */ make_kuid(u0:v10000:r10000, u1000) = v11000h]hX i_uid_into_vfsuid(k21000): /* Map the filesystem's kernel id up into a userspace id. */ from_kuid(u0:k20000:r10000, k21000) = u1000 /* Map the filesystem's userspace id down into a VFS id in the mount's idmapping. */ make_kuid(u0:v10000:r10000, u1000) = v11000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hFinally, when the kernel reports the owner to the caller it will turn the VFS id in the mount's idmapping into a userspace id in the caller's idmapping::h]hFinally, when the kernel reports the owner to the caller it will turn the VFS id in the mount’s idmapping into a userspace id in the caller’s idmapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hMk11000 = vfsuid_into_kuid(v11000) from_kuid(u0:k10000:r10000, k11000) = u1000h]hMk11000 = vfsuid_into_kuid(v11000) from_kuid(u0:k10000:r10000, k11000) = u1000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hWe can test whether this algorithm really works by verifying what happens when we create a new file. Let's say the user is creating a file with ``u1000``.h](hWe can test whether this algorithm really works by verifying what happens when we create a new file. Let’s say the user is creating a file with }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX3The kernel maps this to ``k11000`` in the caller's idmapping. Usually the kernel would now apply the crossmapping, verifying that ``k11000`` can be mapped to a userspace id in the filesystem's idmapping. Since ``k11000`` can't be mapped up in the filesystem's idmapping directly this creation request fails.h](hThe kernel maps this to }(hj hhhNhNubj )}(h ``k11000``h]hk11000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhb in the caller’s idmapping. Usually the kernel would now apply the crossmapping, verifying that }(hj hhhNhNubj )}(h ``k11000``h]hk11000}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhH can be mapped to a userspace id in the filesystem’s idmapping. Since }(hj hhhNhNubj )}(h ``k11000``h]hk11000}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh[ can’t be mapped up in the filesystem’s idmapping directly this creation request fails.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hBut when the caller is accessing the file on an idmapped mount the kernel will first call ``mapped_fs*id()`` thereby translating the caller's kernel id into a VFS id according to the mount's idmapping::h](hZBut when the caller is accessing the file on an idmapped mount the kernel will first call }(hjQhhhNhNubj )}(h``mapped_fs*id()``h]hmapped_fs*id()}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjQubha thereby translating the caller’s kernel id into a VFS id according to the mount’s idmapping:}(hjQhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX$mapped_fsuid(k11000): /* Map the caller's kernel id up into a userspace id in the mount's idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000 /* Map the mount's userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(u0:v20000:r10000, u1000) = v21000h]hX$mapped_fsuid(k11000): /* Map the caller's kernel id up into a userspace id in the mount's idmapping. */ from_kuid(u0:k10000:r10000, k11000) = u1000 /* Map the mount's userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(u0:v20000:r10000, u1000) = v21000}hjqsbah}(h]h ]h"]h$]h&]hhuh1hhhhM hjhhubh)}(hwWhen finally writing to disk the kernel will then map ``v21000`` up into a userspace id in the filesystem's idmapping::h](h6When finally writing to disk the kernel will then map }(hjhhhNhNubj )}(h ``v21000``h]hv21000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh8 up into a userspace id in the filesystem’s idmapping:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hMk21000 = vfsuid_into_kuid(v21000) from_kuid(u0:k20000:r10000, k21000) = u1000h]hMk21000 = vfsuid_into_kuid(v21000) from_kuid(u0:k20000:r10000, k21000) = u1000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjhhubh)}(hAs we can see, we end up with an invertible and therefore information preserving algorithm. A file created from ``u1000`` on an idmapped mount will also be reported as being owned by ``u1000`` and vica versa.h](hpAs we can see, we end up with an invertible and therefore information preserving algorithm. A file created from }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh> on an idmapped mount will also be reported as being owned by }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and vica versa.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(haLet's now briefly reconsider the failing examples from earlier in the context of idmapped mounts.h]hcLet’s now briefly reconsider the failing examples from earlier in the context of idmapped mounts.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]remapping-helpersah ]h"]remapping helpersah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hExample 2 reconsideredh]hExample 2 reconsidered}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hcaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000 mount idmapping: u0:v10000:r10000h]hcaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k20000:r10000 mount idmapping: u0:v10000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhM"hjhhubh)}(hWhen the caller is using a non-initial idmapping the common case is to attach the same idmapping to the mount. We now perform three steps:h]hWhen the caller is using a non-initial idmapping the common case is to attach the same idmapping to the mount. We now perform three steps:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM'hjhhubj )}(hhh](j,)}(hyMap the caller's userspace ids into kernel ids in the caller's idmapping:: make_kuid(u0:k10000:r10000, u1000) = k11000 h](h)}(hJMap the caller's userspace ids into kernel ids in the caller's idmapping::h]hMMap the caller’s userspace ids into kernel ids in the caller’s idmapping:}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM*hj%ubh)}(h+make_kuid(u0:k10000:r10000, u1000) = k11000h]h+make_kuid(u0:k10000:r10000, u1000) = k11000}hj7sbah}(h]h ]h"]h$]h&]hhuh1hhhhM,hj%ubeh}(h]h ]h"]h$]h&]uh1j+hj"hhhhhNubj,)}(hXbTranslate the caller's VFS id into a kernel id in the filesystem's idmapping:: mapped_fsuid(v11000): /* Map the VFS id up into a userspace id in the mount's idmapping. */ from_kuid(u0:v10000:r10000, v11000) = u1000 /* Map the userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(u0:k20000:r10000, u1000) = k21000 h](h)}(hNTranslate the caller's VFS id into a kernel id in the filesystem's idmapping::h]hQTranslate the caller’s VFS id into a kernel id in the filesystem’s idmapping:}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM.hjKubh)}(hX mapped_fsuid(v11000): /* Map the VFS id up into a userspace id in the mount's idmapping. */ from_kuid(u0:v10000:r10000, v11000) = u1000 /* Map the userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(u0:k20000:r10000, u1000) = k21000h]hX mapped_fsuid(v11000): /* Map the VFS id up into a userspace id in the mount's idmapping. */ from_kuid(u0:v10000:r10000, v11000) = u1000 /* Map the userspace id down into a kernel id in the filesystem's idmapping. */ make_kuid(u0:k20000:r10000, u1000) = k21000}hj]sbah}(h]h ]h"]h$]h&]hhuh1hhhhM1hjKubeh}(h]h ]h"]h$]h&]uh1j+hj"hhhhhNubj,)}(hVerify that the caller's kernel ids can be mapped to userspace ids in the filesystem's idmapping:: from_kuid(u0:k20000:r10000, k21000) = u1000 h](h)}(hbVerify that the caller's kernel ids can be mapped to userspace ids in the filesystem's idmapping::h]heVerify that the caller’s kernel ids can be mapped to userspace ids in the filesystem’s idmapping:}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM8hjqubh)}(h+from_kuid(u0:k20000:r10000, k21000) = u1000h]h+from_kuid(u0:k20000:r10000, k21000) = u1000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhM;hjqubeh}(h]h ]h"]h$]h&]uh1j+hj"hhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hjhhhhhM*ubh)}(h6So the ownership that lands on disk will be ``u1000``.h](h,So the ownership that lands on disk will be }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM=hjhhubeh}(h]example-2-reconsideredah ]h"]example 2 reconsideredah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hExample 3 reconsideredh]hExample 3 reconsidered}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM@ubh)}(hcaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k0:r4294967295 mount idmapping: u0:v10000:r10000h]hcaller id: u1000 caller idmapping: u0:k10000:r10000 filesystem idmapping: u0:k0:r4294967295 mount idmapping: u0:v10000:r10000}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMDhjhhubh)}(hSo ultimately the file will be created with ``u1000`` on disk.h](h,So ultimately the file will be created with }(hjhhhNhNubj )}(h ``u1000``h]hu1000}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh on disk.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj5hhubh)}(hfNow let's briefly look at what ownership the caller with id ``u1125`` will see on their work computer:h](h>Now let’s briefly look at what ownership the caller with id }(hjhhhNhNubj )}(h ``u1125``h]hu1125}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh! will see on their work computer:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj5hhubh)}(hfile id: u1000 caller idmapping: u0:k0:r4294967295 filesystem idmapping: u0:k0:r4294967295 mount idmapping: u1000:v1125:r1h]hfile id: u1000 caller idmapping: u0:k0:r4294967295 filesystem idmapping: u0:k0:r4294967295 mount idmapping: u1000:v1125:r1}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj5hhubj )}(hhh](j,)}(hMap the userspace id on disk down into a kernel id in the filesystem's idmapping:: make_kuid(u0:k0:r4294967295, u1000) = k1000 h](h)}(hRMap the userspace id on disk down into a kernel id in the filesystem's idmapping::h]hSMap the userspace id on disk down into a kernel id in the filesystem’s idmapping:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubh)}(h+make_kuid(u0:k0:r4294967295, u1000) = k1000h]h+make_kuid(u0:k0:r4294967295, u1000) = k1000}hj sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj ubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(hXVTranslate the kernel id into a VFS id in the mount's idmapping:: i_uid_into_vfsuid(k1000): /* Map the kernel id up into a userspace id in the filesystem's idmapping. */ from_kuid(u0:k0:r4294967295, k1000) = u1000 /* Map the userspace id down into a VFS id in the mounts's idmapping. */ make_kuid(u1000:v1125:r1, u1000) = v1125 h](h)}(h@Translate the kernel id into a VFS id in the mount's idmapping::h]hATranslate the kernel id into a VFS id in the mount’s idmapping:}(hj* hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj& ubh)}(hXi_uid_into_vfsuid(k1000): /* Map the kernel id up into a userspace id in the filesystem's idmapping. */ from_kuid(u0:k0:r4294967295, k1000) = u1000 /* Map the userspace id down into a VFS id in the mounts's idmapping. */ make_kuid(u1000:v1125:r1, u1000) = v1125h]hXi_uid_into_vfsuid(k1000): /* Map the kernel id up into a userspace id in the filesystem's idmapping. */ from_kuid(u0:k0:r4294967295, k1000) = u1000 /* Map the userspace id down into a VFS id in the mounts's idmapping. */ make_kuid(u1000:v1125:r1, u1000) = v1125}hj8 sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhj& ubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubj,)}(hMap the VFS id up into a userspace id in the caller's idmapping:: k1125 = vfsuid_into_kuid(v1125) from_kuid(u0:k0:r4294967295, k1125) = u1125 h](h)}(hAMap the VFS id up into a userspace id in the caller's idmapping::h]hBMap the VFS id up into a userspace id in the caller’s idmapping:}(hjP hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjL ubh)}(hKk1125 = vfsuid_into_kuid(v1125) from_kuid(u0:k0:r4294967295, k1125) = u1125h]hKk1125 = vfsuid_into_kuid(v1125) from_kuid(u0:k0:r4294967295, k1125) = u1125}hj^ sbah}(h]h ]h"]h$]h&]hhuh1hhhhMhjL ubeh}(h]h ]h"]h$]h&]uh1j+hjhhhhhNubeh}(h]h ]h"]h$]h&]j j j hj j uh1j hj5hhhhhMubh)}(hSo ultimately the caller will be reported that the file belongs to ``u1125`` which is the caller's userspace id on their workstation in our example.h](hCSo ultimately the caller will be reported that the file belongs to }(hjx hhhNhNubj )}(h ``u1125``h]hu1125}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjx ubhJ which is the caller’s userspace id on their workstation in our example.}(hjx hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj5hhubh)}(hX!The raw userspace id that is put on disk is ``u1000`` so when the user takes their home directory back to their home computer where they are assigned ``u1000`` using the initial idmapping and mount the filesystem with the initial idmapping they will see all those files owned by ``u1000``.h](h,The raw userspace id that is put on disk is }(hj hhhNhNubj )}(h ``u1000``h]hu1000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubha so when the user takes their home directory back to their home computer where they are assigned }(hj hhhNhNubj )}(h ``u1000``h]hu1000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhx using the initial idmapping and mount the filesystem with the initial idmapping they will see all those files owned by }(hj hhhNhNubj )}(h ``u1000``h]hu1000}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj5hhubeh}(h]&changing-ownership-on-a-home-directoryah ]h"]&changing ownership on a home directoryah$]h&]uh1hhjhhhhhMubeh}(h]idmappings-on-idmapped-mountsah ]h"]idmappings on idmapped mountsah$]h&]uh1hhhhhhhhM)ubeh}(h] idmappingsah ]h"] idmappingsah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj!error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j j j j jLjIj9 j6 j> j; j j j1 j. jjjjj<j9j7j4jjjjj j jjjjjjjjjbj_j2j/j j u nametypes}(j j jLj9 j> j j1 jjj<j7jjj jjjjjbj2j uh}(j hj hjIjj6 jOj; jnj jA j. j jj< jj j9jj4j?jj:jjj jjjljjjjjjj_jj/jej j5u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.