Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
fengjianxinghun
V2EX  ›  Linux

当调用原始 syscall 填充__user 空间指针后,紧接着访问这个指针是否需要 copy_from_user?

  •  
  •   fengjianxinghun · Aug 2, 2021 · 1507 views
    This topic created in 1772 days ago, the information mentioned may be changed or developed.

    这里我做了 access_ok 检测 msg 指针,安全起见是否需要 copy_from_user ?

            ret = KHOOK_ORIGIN(sys_recvmsg, sockfd, msg, flags);
    
    	/* Some error occured. Don't do anything. */
    	if (ret < 0)
    		return ret;
    
    	/* check __user addr is safe */
    	if (!access_ok(msg, sizeof(struct msghdr)) {
    		return ret;
    	}
    
    	/* Extract netlink message header from message */
    	nlh = (struct nlmsghdr *)(msg->msg_iov->iov_base);
    	if (nlh == NULL) {
    		//printk(KERN_WARNING "nlmsghdr is null");
    		return ret;
    	}
    
    2 replies    2021-08-11 00:27:44 +08:00
    tomychen
        1
    tomychen  
       Aug 10, 2021
    看代码就是,你最终都要操作 msg,为啥不直接调 copy_from_user 一份出来呢?
    fengjianxinghun
        2
    fengjianxinghun  
    OP
       Aug 11, 2021
    @tomychen 要修改内容,又需要 copy 回去。就是不想动这个。意味着你拷贝的时候要拷贝 msg 到拷贝 iov_base,这里面的嵌套很讨厌。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   926 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:37 · PVG 05:37 · LAX 14:37 · JFK 17:37
    ♥ Do have faith in what you're doing.