Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_HIGHUID_H
0003 #define _LINUX_HIGHUID_H
0004 
0005 #include <linux/types.h>
0006 
0007 /*
0008  * general notes:
0009  *
0010  * CONFIG_UID16 is defined if the given architecture needs to
0011  * support backwards compatibility for old system calls.
0012  *
0013  * kernel code should use uid_t and gid_t at all times when dealing with
0014  * kernel-private data.
0015  *
0016  * old_uid_t and old_gid_t should only be different if CONFIG_UID16 is
0017  * defined, else the platform should provide dummy typedefs for them
0018  * such that they are equivalent to __kernel_{u,g}id_t.
0019  *
0020  * uid16_t and gid16_t are used on all architectures. (when dealing
0021  * with structures hard coded to 16 bits, such as in filesystems)
0022  */
0023 
0024 
0025 /*
0026  * This is the "overflow" UID and GID. They are used to signify uid/gid
0027  * overflow to old programs when they request uid/gid information but are
0028  * using the old 16 bit interfaces.
0029  * When you run a libc5 program, it will think that all highuid files or
0030  * processes are owned by this uid/gid.
0031  * The idea is that it's better to do so than possibly return 0 in lieu of
0032  * 65536, etc.
0033  */
0034 
0035 extern int overflowuid;
0036 extern int overflowgid;
0037 
0038 extern void __bad_uid(void);
0039 extern void __bad_gid(void);
0040 
0041 #define DEFAULT_OVERFLOWUID 65534
0042 #define DEFAULT_OVERFLOWGID 65534
0043 
0044 #ifdef CONFIG_UID16
0045 
0046 /* prevent uid mod 65536 effect by returning a default value for high UIDs */
0047 #define high2lowuid(uid) ((uid) & ~0xFFFF ? (old_uid_t)overflowuid : (old_uid_t)(uid))
0048 #define high2lowgid(gid) ((gid) & ~0xFFFF ? (old_gid_t)overflowgid : (old_gid_t)(gid))
0049 /*
0050  * -1 is different in 16 bits than it is in 32 bits
0051  * these macros are used by chown(), setreuid(), ...,
0052  */
0053 #define low2highuid(uid) ((uid) == (old_uid_t)-1 ? (uid_t)-1 : (uid_t)(uid))
0054 #define low2highgid(gid) ((gid) == (old_gid_t)-1 ? (gid_t)-1 : (gid_t)(gid))
0055 
0056 #define __convert_uid(size, uid) \
0057     (size >= sizeof(uid) ? (uid) : high2lowuid(uid))
0058 #define __convert_gid(size, gid) \
0059     (size >= sizeof(gid) ? (gid) : high2lowgid(gid))
0060     
0061 
0062 #else
0063 
0064 #define __convert_uid(size, uid) (uid)
0065 #define __convert_gid(size, gid) (gid)
0066 
0067 #endif /* !CONFIG_UID16 */
0068 
0069 /* uid/gid input should be always 32bit uid_t */
0070 #define SET_UID(var, uid) do { (var) = __convert_uid(sizeof(var), (uid)); } while (0)
0071 #define SET_GID(var, gid) do { (var) = __convert_gid(sizeof(var), (gid)); } while (0)
0072 
0073 /*
0074  * Everything below this line is needed on all architectures, to deal with
0075  * filesystems that only store 16 bits of the UID/GID, etc.
0076  */
0077 
0078 /*
0079  * This is the UID and GID that will get written to disk if a filesystem
0080  * only supports 16-bit UIDs and the kernel has a high UID/GID to write
0081  */
0082 extern int fs_overflowuid;
0083 extern int fs_overflowgid;
0084 
0085 #define DEFAULT_FS_OVERFLOWUID  65534
0086 #define DEFAULT_FS_OVERFLOWGID  65534
0087 
0088 /*
0089  * Since these macros are used in architectures that only need limited
0090  * 16-bit UID back compatibility, we won't use old_uid_t and old_gid_t
0091  */
0092 #define fs_high2lowuid(uid) ((uid) & ~0xFFFF ? (uid16_t)fs_overflowuid : (uid16_t)(uid))
0093 #define fs_high2lowgid(gid) ((gid) & ~0xFFFF ? (gid16_t)fs_overflowgid : (gid16_t)(gid))
0094 
0095 #define low_16_bits(x)  ((x) & 0xFFFF)
0096 #define high_16_bits(x) (((x) & 0xFFFF0000) >> 16)
0097 
0098 #endif /* _LINUX_HIGHUID_H */