Skip to content

Commit df2c2af

Browse files
Mimi ZoharJames Morris
authored andcommitted
ima: eliminate passing d_name.name to process_measurement()
Passing a pointer to the dentry name, as a parameter to process_measurement(), causes a race condition with rename() and is unnecessary, as the dentry name is already accessible via the file parameter. In the normal case, we use the full pathname as provided by brpm->filename, bprm->interp, or ima_d_path(). Only on ima_d_path() failure, do we fallback to using the d_name.name, which points either to external memory or d_iname. Reported-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com> Signed-off-by: James Morris <james.l.morris@oracle.com>
1 parent 958d2c2 commit df2c2af

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎security/integrity/ima/ima_main.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,9 @@ static int process_measurement(struct file *file, const char *filename,
189189
if (rc != 0)
190190
goto out_digsig;
191191

192-
if (function != BPRM_CHECK)
193-
pathname = ima_d_path(&file->f_path, &pathbuf);
194-
192+
pathname = !filename ? ima_d_path(&file->f_path, &pathbuf) : filename;
195193
if (!pathname)
196-
pathname = filename;
194+
pathname = (const char *)file->f_dentry->d_name.name;
197195

198196
if (action & IMA_MEASURE)
199197
ima_store_measurement(iint, file, pathname);
@@ -226,8 +224,7 @@ static int process_measurement(struct file *file, const char *filename,
226224
int ima_file_mmap(struct file *file, unsigned long prot)
227225
{
228226
if (file && (prot & PROT_EXEC))
229-
return process_measurement(file, file->f_dentry->d_name.name,
230-
MAY_EXEC, MMAP_CHECK);
227+
return process_measurement(file, NULL, MAY_EXEC, MMAP_CHECK);
231228
return 0;
232229
}
233230

@@ -265,7 +262,7 @@ int ima_bprm_check(struct linux_binprm *bprm)
265262
int ima_file_check(struct file *file, int mask)
266263
{
267264
ima_rdwr_violation_check(file);
268-
return process_measurement(file, file->f_dentry->d_name.name,
265+
return process_measurement(file, NULL,
269266
mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
270267
FILE_CHECK);
271268
}
@@ -290,8 +287,7 @@ int ima_module_check(struct file *file)
290287
#endif
291288
return 0; /* We rely on module signature checking */
292289
}
293-
return process_measurement(file, file->f_dentry->d_name.name,
294-
MAY_EXEC, MODULE_CHECK);
290+
return process_measurement(file, NULL, MAY_EXEC, MODULE_CHECK);
295291
}
296292

297293
static int __init init_ima(void)

0 commit comments

Comments
 (0)