lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 29 Mar 2007 15:29:57 +0800
From:	"" <linwy@...l.ustc.edu.cn>
To:	linux-kernel@...r.kernel.org
Subject: a question about kernel copy userspace data

hello ,
i am programming a trial firewall based on netfilter ,which needs the module to
access the data of user space ,so i use copy_from_user() but it can't work ,the
code(simple test code) is like this:
-------user space program-----
#include <stdlib.h>
#include <stdio.h>

int main(int argc ,char *argv[]) {
char para[100]="insmod test.ko ";
int c=24;
unsigned int point=&c;
printf("%u\n",point);
char b[11]="0000000000"; /*convert the unsigned to chars */
int j=10;
int siz=0;
while(point>0) {
b[--j]=point%10+48;
point=point/10;
siz++;
}
char ips[30]="point=";
strcat(ips,&b[10-siz]);
strcat(para,ips);
puts(para);
system("make");
system(para);
}
-------kernel module-----------
#include <linux/module.h>
#include <linux/netfilter_ipv4.h>
#include <linux/tcp.h>
#include <linux/moduleparam.h>

MODULE_LICENSE("Dual BSD/GPL");

static unsigned int *point;
module_param(point, uint , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
MODULE_PARM_DESC(point, "the pointer of user space");

static unsigned int
linuxmag_hook(unsigned int hook, struct sk_buff **pskb,
const struct net_device *indev, const
struct net_device *outdev, int
(*okfn)(struct sk_buff *))
{
printk("world\n");
printk(" %u\n",point);
int *b;
b=kmalloc(sizeof(int),GFP_KERNEL);
copy_from_user(b,(int *)point,sizeof(int));
printk("user space's value=%u\n",*b);
}

static struct nf_hook_ops linuxmag_ops
= { .hook = linuxmag_hook,
.owner = THIS_MODULE,
.pf = PF_INET,
.hooknum = NF_IP_LOCAL_OUT,
.priority = NF_IP_PRI_FILTER-1
};

static int __init init(void)
{
return nf_register_hook(&linuxmag_ops);
}

static void __exit fini(void)
{
nf_unregister_hook(&linuxmag_ops);
}
module_init(init);
module_exit(fini);

i check the /var/log/messages.
 the user space's value is 0
not the right value 24 which i defined in main().
this question puzzled me for a few days,and i am a fresh man about  kernel.is
there anyone can help me?
any answer would be appreciated very much .


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists