On Tue, Apr 26, 2022 at 07:11:27PM +0800, Yang Xu wrote: > +umode_t mode_strip_sgid(struct user_namespace *mnt_userns, > + const struct inode *dir, umode_t mode) > +{ > + if (S_ISDIR(mode) || !dir || !(dir->i_mode & S_ISGID)) > + return mode; > + if ((mode & (S_ISGID | S_IXGRP)) != (S_ISGID | S_IXGRP)) > + return mode; > + if (in_group_p(i_gid_into_mnt(mnt_userns, dir))) > + return mode; > + if (capable_wrt_inode_uidgid(mnt_userns, dir, CAP_FSETID)) > + return mode; > + > + mode &= ~S_ISGID; > + return mode; > +} I'm fairly sure that absolute majority of calls will not have S_ISGID passed in mode. So I'd prefer to reorder the first two ifs.