• R/O
  • SSH
  • HTTPS

akari: Commit


Commit MetaInfo

Revision492 (tree)
Time2015-04-06 15:08:35
Authorkumaneko

Log Message

(empty log message)

Change Summary

Incremental Difference

--- trunk/akari/realpath.c (revision 491)
+++ trunk/akari/realpath.c (revision 492)
@@ -27,17 +27,17 @@
2727
2828 char *ccs_encode(const char *str);
2929 char *ccs_encode2(const char *str, int str_len);
30-char *ccs_realpath(struct path *path);
30+char *ccs_realpath(const struct path *path);
3131 const char *ccs_get_exe(void);
3232 void ccs_fill_path_info(struct ccs_path_info *ptr);
3333
34-static char *ccs_get_absolute_path(struct path *path, char * const buffer,
35- const int buflen);
34+static char *ccs_get_absolute_path(const struct path *path,
35+ char * const buffer, const int buflen);
3636 static char *ccs_get_dentry_path(struct dentry *dentry, char * const buffer,
3737 const int buflen);
3838 static char *ccs_get_local_path(struct dentry *dentry, char * const buffer,
3939 const int buflen);
40-static char *ccs_get_socket_name(struct path *path, char * const buffer,
40+static char *ccs_get_socket_name(const struct path *path, char * const buffer,
4141 const int buflen);
4242 static int ccs_const_part_length(const char *filename);
4343
@@ -213,8 +213,8 @@
213213 *
214214 * If dentry is a directory, trailing '/' is appended.
215215 */
216-static char *ccs_get_absolute_path(struct path *path, char * const buffer,
217- const int buflen)
216+static char *ccs_get_absolute_path(const struct path *path,
217+ char * const buffer, const int buflen)
218218 {
219219 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
220220 char *pos = ERR_PTR(-ENOMEM);
@@ -343,9 +343,20 @@
343343 static char *ccs_get_dentry_path(struct dentry *dentry, char * const buffer,
344344 const int buflen)
345345 {
346-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
346+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
347347 char *pos = ERR_PTR(-ENOMEM);
348348 if (buflen >= 256) {
349+ pos = dentry_path_raw(dentry, buffer, buflen - 1);
350+ if (!IS_ERR(pos) && *pos == '/' && pos[1] &&
351+ d_is_dir(dentry)) {
352+ buffer[buflen - 2] = '/';
353+ buffer[buflen - 1] = '\0';
354+ }
355+ }
356+ return pos;
357+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
358+ char *pos = ERR_PTR(-ENOMEM);
359+ if (buflen >= 256) {
349360 /* rename_lock is locked/unlocked by dentry_path_raw(). */
350361 pos = dentry_path_raw(dentry, buffer, buflen - 1);
351362 if (!IS_ERR(pos) && *pos == '/' && pos[1]) {
@@ -478,7 +489,7 @@
478489 *
479490 * Returns the buffer.
480491 */
481-static char *ccs_get_socket_name(struct path *path, char * const buffer,
492+static char *ccs_get_socket_name(const struct path *path, char * const buffer,
482493 const int buflen)
483494 {
484495 struct inode *inode = path->dentry->d_inode;
@@ -506,7 +517,7 @@
506517 * This function uses kzalloc(), so caller must kfree() if this function
507518 * didn't return NULL.
508519 */
509-char *ccs_realpath(struct path *path)
520+char *ccs_realpath(const struct path *path)
510521 {
511522 char *buf = NULL;
512523 char *name = NULL;
@@ -717,30 +728,40 @@
717728 const char *ccs_get_exe(void)
718729 {
719730 struct mm_struct *mm = current->mm;
720-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
731+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
721732 struct vm_area_struct *vma;
722733 #endif
723- const char *cp = NULL;
734+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
735+ struct path path;
736+#endif
737+ struct file *exe_file = NULL;
738+ const char *cp;
724739 if (!mm)
725740 return NULL;
726741 down_read(&mm->mmap_sem);
727-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
728- if (mm->exe_file)
729- cp = ccs_realpath(&mm->exe_file->f_path);
742+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
743+ /* Not using get_mm_exe_file() as it is not exported. */
744+ exe_file = mm->exe_file;
730745 #else
731746 for (vma = mm->mmap; vma; vma = vma->vm_next) {
732747 if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) {
733-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
734- struct path path = { vma->vm_file->f_vfsmnt,
735- vma->vm_file->f_dentry };
736- cp = ccs_realpath(&path);
737-#else
738- cp = ccs_realpath(&vma->vm_file->f_path);
739-#endif
748+ exe_file = vma->vm_file;
740749 break;
741750 }
742751 }
743752 #endif
753+ if (exe_file)
754+ get_file(exe_file);
744755 up_read(&mm->mmap_sem);
756+ if (!exe_file)
757+ return NULL;
758+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
759+ cp = ccs_realpath(&exe_file->f_path);
760+#else
761+ path.mnt = exe_file->f_vfsmnt;
762+ path.dentry = exe_file->f_dentry;
763+ cp = ccs_realpath(&path);
764+#endif
765+ fput(exe_file);
745766 return cp;
746767 }
--- trunk/akari/internal.h (revision 491)
+++ trunk/akari/internal.h (revision 492)
@@ -1594,7 +1594,7 @@
15941594 bool ccs_memory_ok(const void *ptr, const unsigned int size);
15951595 char *ccs_encode(const char *str);
15961596 char *ccs_encode2(const char *str, int str_len);
1597-char *ccs_realpath(struct path *path);
1597+char *ccs_realpath(const struct path *path);
15981598 const char *ccs_get_exe(void);
15991599 const struct ccs_path_info *ccs_get_name(const char *name);
16001600 int ccs_audit_log(struct ccs_request_info *r);
--- trunk/akari/permission.c (revision 491)
+++ trunk/akari/permission.c (revision 492)
@@ -2302,9 +2302,14 @@
23022302 return 0;
23032303 #endif
23042304 #ifndef CONFIG_CCSECURITY_FILE_GETATTR
2305+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
2306+ if (d_is_dir(dentry))
2307+ return 0;
2308+#else
23052309 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))
23062310 return 0;
23072311 #endif
2312+#endif
23082313 buf.name = NULL;
23092314 r.mode = CCS_CONFIG_DISABLED;
23102315 idx = ccs_read_lock();
@@ -2513,8 +2518,13 @@
25132518 switch (operation) {
25142519 case CCS_TYPE_RENAME:
25152520 case CCS_TYPE_LINK:
2521+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
2522+ if (!d_is_dir(dentry1))
2523+ break;
2524+#else
25162525 if (!dentry1->d_inode || !S_ISDIR(dentry1->d_inode->i_mode))
25172526 break;
2527+#endif
25182528 /* fall through */
25192529 case CCS_TYPE_PIVOT_ROOT:
25202530 ccs_add_slash(&buf1);
--- trunk/akari/lsm.c (revision 491)
+++ trunk/akari/lsm.c (revision 492)
@@ -1030,9 +1030,29 @@
10301030
10311031 #endif
10321032
1033+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
1034+
10331035 /**
10341036 * ccs_inode_getattr - Check permission for stat().
10351037 *
1038+ * @path: Pointer to "struct path".
1039+ *
1040+ * Returns 0 on success, negative value otherwise.
1041+ */
1042+static int ccs_inode_getattr(const struct path *path)
1043+{
1044+ int rc = ccs_getattr_permission(path->mnt, path->dentry);
1045+ if (rc)
1046+ return rc;
1047+ while (!original_security_ops.inode_getattr);
1048+ return original_security_ops.inode_getattr(path);
1049+}
1050+
1051+#else
1052+
1053+/**
1054+ * ccs_inode_getattr - Check permission for stat().
1055+ *
10361056 * @mnt: Pointer to "struct vfsmount".
10371057 * @dentry: Pointer to "struct dentry".
10381058 *
@@ -1047,6 +1067,8 @@
10471067 return original_security_ops.inode_getattr(mnt, dentry);
10481068 }
10491069
1070+#endif
1071+
10501072 #if defined(CONFIG_SECURITY_PATH)
10511073
10521074 #if defined(USE_UMODE_T)
Show on old repository browser