@@ -166,42 +166,42 @@ static int common_perm(const char *op, const struct path *path, u32 mask,
166166}
167167
168168/**
169- * common_perm_dir_dentry - common permission wrapper when path is dir, dentry
169+ * common_perm_cond - common permission wrapper around inode cond
170170 * @op: operation being checked
171- * @dir: directory of the dentry (NOT NULL)
172- * @dentry: dentry to check (NOT NULL)
171+ * @path: location to check (NOT NULL)
173172 * @mask: requested permissions mask
174- * @cond: conditional info for the permission request (NOT NULL)
175173 *
176174 * Returns: %0 else error code if error or permission denied
177175 */
178- static int common_perm_dir_dentry (const char * op , const struct path * dir ,
179- struct dentry * dentry , u32 mask ,
180- struct path_cond * cond )
176+ static int common_perm_cond (const char * op , const struct path * path , u32 mask )
181177{
182- struct path path = { .mnt = dir -> mnt , .dentry = dentry };
178+ struct path_cond cond = { d_backing_inode (path -> dentry )-> i_uid ,
179+ d_backing_inode (path -> dentry )-> i_mode
180+ };
183181
184- return common_perm (op , & path , mask , cond );
182+ if (!path_mediated_fs (path -> dentry ))
183+ return 0 ;
184+
185+ return common_perm (op , path , mask , & cond );
185186}
186187
187188/**
188- * common_perm_path - common permission wrapper when mnt , dentry
189+ * common_perm_dir_dentry - common permission wrapper when path is dir , dentry
189190 * @op: operation being checked
190- * @path: location to check (NOT NULL)
191+ * @dir: directory of the dentry (NOT NULL)
192+ * @dentry: dentry to check (NOT NULL)
191193 * @mask: requested permissions mask
194+ * @cond: conditional info for the permission request (NOT NULL)
192195 *
193196 * Returns: %0 else error code if error or permission denied
194197 */
195- static inline int common_perm_path (const char * op , const struct path * path ,
196- u32 mask )
198+ static int common_perm_dir_dentry (const char * op , const struct path * dir ,
199+ struct dentry * dentry , u32 mask ,
200+ struct path_cond * cond )
197201{
198- struct path_cond cond = { d_backing_inode (path -> dentry )-> i_uid ,
199- d_backing_inode (path -> dentry )-> i_mode
200- };
201- if (!path_mediated_fs (path -> dentry ))
202- return 0 ;
202+ struct path path = { .mnt = dir -> mnt , .dentry = dentry };
203203
204- return common_perm (op , path , mask , & cond );
204+ return common_perm (op , & path , mask , cond );
205205}
206206
207207/**
@@ -274,7 +274,7 @@ static int apparmor_path_mknod(const struct path *dir, struct dentry *dentry,
274274
275275static int apparmor_path_truncate (const struct path * path )
276276{
277- return common_perm_path (OP_TRUNC , path , MAY_WRITE | AA_MAY_META_WRITE );
277+ return common_perm_cond (OP_TRUNC , path , MAY_WRITE | AA_MAY_META_WRITE );
278278}
279279
280280static int apparmor_path_symlink (const struct path * dir , struct dentry * dentry ,
@@ -333,17 +333,17 @@ static int apparmor_path_rename(const struct path *old_dir, struct dentry *old_d
333333
334334static int apparmor_path_chmod (const struct path * path , umode_t mode )
335335{
336- return common_perm_path (OP_CHMOD , path , AA_MAY_CHMOD );
336+ return common_perm_cond (OP_CHMOD , path , AA_MAY_CHMOD );
337337}
338338
339339static int apparmor_path_chown (const struct path * path , kuid_t uid , kgid_t gid )
340340{
341- return common_perm_path (OP_CHOWN , path , AA_MAY_CHOWN );
341+ return common_perm_cond (OP_CHOWN , path , AA_MAY_CHOWN );
342342}
343343
344344static int apparmor_inode_getattr (const struct path * path )
345345{
346- return common_perm_path (OP_GETATTR , path , AA_MAY_META_READ );
346+ return common_perm_cond (OP_GETATTR , path , AA_MAY_META_READ );
347347}
348348
349349static int apparmor_file_open (struct file * file , const struct cred * cred )
0 commit comments