fs.h (e67fe63341b8117d7e0d9acf0f1222d5138b9266) | fs.h (c14329d39f2daa8132e1bbe5cc531da387bcf44a) |
---|---|
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_FS_H 3#define _LINUX_FS_H 4 5#include <linux/linkage.h> 6#include <linux/wait_bit.h> 7#include <linux/kdev_t.h> 8#include <linux/dcache.h> --- 1730 unchanged lines hidden (view full) --- 1739 if (attr->ia_valid & ATTR_GID) 1740 inode->i_gid = from_vfsgid(mnt_userns, i_user_ns(inode), 1741 attr->ia_vfsgid); 1742} 1743 1744/** 1745 * inode_fsuid_set - initialize inode's i_uid field with callers fsuid 1746 * @inode: inode to initialize | 1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_FS_H 3#define _LINUX_FS_H 4 5#include <linux/linkage.h> 6#include <linux/wait_bit.h> 7#include <linux/kdev_t.h> 8#include <linux/dcache.h> --- 1730 unchanged lines hidden (view full) --- 1739 if (attr->ia_valid & ATTR_GID) 1740 inode->i_gid = from_vfsgid(mnt_userns, i_user_ns(inode), 1741 attr->ia_vfsgid); 1742} 1743 1744/** 1745 * inode_fsuid_set - initialize inode's i_uid field with callers fsuid 1746 * @inode: inode to initialize |
1747 * @mnt_userns: user namespace of the mount the inode was found from | 1747 * @idmap: idmap of the mount the inode was found from |
1748 * 1749 * Initialize the i_uid field of @inode. If the inode was found/created via | 1748 * 1749 * Initialize the i_uid field of @inode. If the inode was found/created via |
1750 * an idmapped mount map the caller's fsuid according to @mnt_users. | 1750 * an idmapped mount map the caller's fsuid according to @idmap. |
1751 */ 1752static inline void inode_fsuid_set(struct inode *inode, | 1751 */ 1752static inline void inode_fsuid_set(struct inode *inode, |
1753 struct user_namespace *mnt_userns) | 1753 struct mnt_idmap *idmap) |
1754{ | 1754{ |
1755 inode->i_uid = mapped_fsuid(mnt_userns, i_user_ns(inode)); | 1755 inode->i_uid = mapped_fsuid(idmap, i_user_ns(inode)); |
1756} 1757 1758/** 1759 * inode_fsgid_set - initialize inode's i_gid field with callers fsgid 1760 * @inode: inode to initialize | 1756} 1757 1758/** 1759 * inode_fsgid_set - initialize inode's i_gid field with callers fsgid 1760 * @inode: inode to initialize |
1761 * @mnt_userns: user namespace of the mount the inode was found from | 1761 * @idmap: idmap of the mount the inode was found from |
1762 * 1763 * Initialize the i_gid field of @inode. If the inode was found/created via | 1762 * 1763 * Initialize the i_gid field of @inode. If the inode was found/created via |
1764 * an idmapped mount map the caller's fsgid according to @mnt_users. | 1764 * an idmapped mount map the caller's fsgid according to @idmap. |
1765 */ 1766static inline void inode_fsgid_set(struct inode *inode, | 1765 */ 1766static inline void inode_fsgid_set(struct inode *inode, |
1767 struct user_namespace *mnt_userns) | 1767 struct mnt_idmap *idmap) |
1768{ | 1768{ |
1769 inode->i_gid = mapped_fsgid(mnt_userns, i_user_ns(inode)); | 1769 inode->i_gid = mapped_fsgid(idmap, i_user_ns(inode)); |
1770} 1771 1772/** 1773 * fsuidgid_has_mapping() - check whether caller's fsuid/fsgid is mapped 1774 * @sb: the superblock we want a mapping in 1775 * @idmap: idmap of the relevant mount 1776 * 1777 * Check whether the caller's fsuid and fsgid have a valid mapping in the 1778 * s_user_ns of the superblock @sb. If the caller is on an idmapped mount map 1779 * the caller's fsuid and fsgid according to the @idmap first. 1780 * 1781 * Return: true if fsuid and fsgid is mapped, false if not. 1782 */ 1783static inline bool fsuidgid_has_mapping(struct super_block *sb, 1784 struct mnt_idmap *idmap) 1785{ 1786 struct user_namespace *fs_userns = sb->s_user_ns; | 1770} 1771 1772/** 1773 * fsuidgid_has_mapping() - check whether caller's fsuid/fsgid is mapped 1774 * @sb: the superblock we want a mapping in 1775 * @idmap: idmap of the relevant mount 1776 * 1777 * Check whether the caller's fsuid and fsgid have a valid mapping in the 1778 * s_user_ns of the superblock @sb. If the caller is on an idmapped mount map 1779 * the caller's fsuid and fsgid according to the @idmap first. 1780 * 1781 * Return: true if fsuid and fsgid is mapped, false if not. 1782 */ 1783static inline bool fsuidgid_has_mapping(struct super_block *sb, 1784 struct mnt_idmap *idmap) 1785{ 1786 struct user_namespace *fs_userns = sb->s_user_ns; |
1787 struct user_namespace *mnt_userns = mnt_idmap_owner(idmap); | |
1788 kuid_t kuid; 1789 kgid_t kgid; 1790 | 1787 kuid_t kuid; 1788 kgid_t kgid; 1789 |
1791 kuid = mapped_fsuid(mnt_userns, fs_userns); | 1790 kuid = mapped_fsuid(idmap, fs_userns); |
1792 if (!uid_valid(kuid)) 1793 return false; | 1791 if (!uid_valid(kuid)) 1792 return false; |
1794 kgid = mapped_fsgid(mnt_userns, fs_userns); | 1793 kgid = mapped_fsgid(idmap, fs_userns); |
1795 if (!gid_valid(kgid)) 1796 return false; 1797 return kuid_has_mapping(fs_userns, kuid) && 1798 kgid_has_mapping(fs_userns, kgid); 1799} 1800 1801extern struct timespec64 current_time(struct inode *inode); 1802 --- 1812 unchanged lines hidden --- | 1794 if (!gid_valid(kgid)) 1795 return false; 1796 return kuid_has_mapping(fs_userns, kuid) && 1797 kgid_has_mapping(fs_userns, kgid); 1798} 1799 1800extern struct timespec64 current_time(struct inode *inode); 1801 --- 1812 unchanged lines hidden --- |