From 1ca090864291d72a5870d2026d8c7355e6748424 Mon Sep 17 00:00:00 2001 From: Tie Liu Date: Thu, 3 Aug 2023 14:46:47 +0800 Subject: [PATCH 1/2] reset set app aot flags by xattr --- bin/daemon.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/daemon.rs b/bin/daemon.rs index 6cbea2d..a0a0350 100644 --- a/bin/daemon.rs +++ b/bin/daemon.rs @@ -283,10 +283,14 @@ fn bolt_optimize_so(conf: &RtoConfig) -> i32 { pub fn set_app_aot_flag(old_path: &String, is_set: bool) -> i32 { let mut args: Vec = Vec::new(); + let setfattr = "setfattr".to_string(); + args.push("-n".to_string()); + args.push("trusted.sysboost_flags".to_string()); + args.push("-v".to_string()); if is_set { - args.push("--set".to_string()); + args.push("true".to_string()); } else { - args.push("--unset".to_string()); + args.push("false".to_string()); } let old_path = Path::new(old_path); let old_path = match fs::canonicalize(old_path) { @@ -305,7 +309,7 @@ pub fn set_app_aot_flag(old_path: &String, is_set: bool) -> i32 { } } args.push(new_path.to_str().unwrap().to_string()); - let ret = run_child(SYSBOOST_PATH, &args); + let ret = run_child(&setfattr, &args); match fs::rename(&new_path, &old_path) { Ok(_) => {} Err(e) => { -- Gitee From faba9ae64b15c5b6d4df81f09ab8b5a40616c1f4 Mon Sep 17 00:00:00 2001 From: Tie Liu Date: Thu, 3 Aug 2023 21:36:20 +0800 Subject: [PATCH 2/2] add feature kernel read xattr --- src/binfmt_rto/binfmt_rto.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/binfmt_rto/binfmt_rto.c b/src/binfmt_rto/binfmt_rto.c index 2c4f9cf..e4a8ee8 100644 --- a/src/binfmt_rto/binfmt_rto.c +++ b/src/binfmt_rto/binfmt_rto.c @@ -46,6 +46,9 @@ #include #include #include +#include +#include + #include #include @@ -1179,6 +1182,10 @@ static int load_elf_binary(struct linux_binprm *bprm) struct arch_elf_state arch_state = INIT_ARCH_ELF_STATE; struct mm_struct *mm; struct pt_regs *regs; + struct dentry *elf_dentry = (struct dentry *)bprm->file->f_path.dentry; + struct inode *elf_inode = (struct inode *)elf_dentry->d_inode; + struct xattr *xattr = NULL; + int xattr_size = 0; #ifdef CONFIG_ELF_SYSBOOST bool is_rto_format = false; @@ -1211,8 +1218,22 @@ load_rto: goto out; #ifdef CONFIG_ELF_SYSBOOST + // try to get attr from bprm + xattr_size = elf_inode->i_op->getattr(elf_dentry, "trusted.flags", xattr, 0); + if (xattr_size > 0) { + xattr = kmalloc(xattr_size + 1, GFP_KERNEL); + if (!xattr) { + retval = -ENOMEM; + goto out; + } + xattr_size = elf_inode->i_op->getattr(elf_dentry, "trusted.flags", xattr, xattr_size); + if (xattr_size < 0) { + retval = -ENOMEM; + goto out; + } + } /* replace app.rto file, then use binfmt */ - if (elf_ex->e_flags & OS_SPECIFIC_FLAG_SYMBOLIC_LINK) { + if (!memcmp(xattr, "true", xattr_size)) { int ret = try_replace_file(bprm); if (!ret) { if (elf_ex->e_flags & OS_SPECIFIC_FLAG_RTO) { -- Gitee