커널에서 krealloc같은 명령어는 없나요? 꼭 도움 부탁드립니다.

ilgoddes의 이미지

안녕하세요...

요즘 커널 프로그래밍에서도 NFS 부분을 열심히 하고 있는데요...

nfs_file_write함수를 보면
(const char*)buf부분이 있는데요...
buf의 내용을 바꾸는것은 되는데...

buf의 크기를 바꿔야 되거든요...

그런데 다른 변수(예를 들어 buf2)를 잡아서 kmalloc로 buf만큼 할당하고 값 집어넣고...
리턴값을 잡은 다른 변수로 바꿔서 했는데...

컴파일 하고 예를 들어 cp명령어를 주면
cp: writing 'nfs/XXXXX' : Bad address 이런 에러가 나면서 안되네요...

buf영역에 잡혀있는 메모리와 buf2영역에 잡혀있는 메모리가 주소가 달라서 그런것 같은데...

만약 라이브러리에 있는realloc같은 함수가 있으면 가능할 것도 같은데...
도저히 안되네요...

벌써 며칠째 이것때문에 삽질중입니다...

밑에 소스 올려 놓겠습니다...
보시고 꼭 도움 부탁드립니다...

static ssize_t nfs_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
{
//added start
	//int i;
	int size = 1;
	char user_w_buf[1];
	char *w_buf;
	char *back_w_buf = (char *)buf;

	char *buf2 = {0,};
	char **a_buf = (char*)&buf;
	char **a_buf2 = &buf2;
//added end



//여기는 본래 있던 함수들...	
	struct dentry * dentry = file->f_dentry;
	struct inode * inode = dentry->d_inode;
	ssize_t result;

	dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%lu)\n",
		dentry->d_parent->d_name.name, dentry->d_name.name,
		inode->i_ino, (unsigned long) count, (unsigned long) *ppos);

	result = -EBUSY;
	if (IS_SWAPFILE(inode))
		goto out_swapfile;
	result = nfs_revalidate_inode(NFS_SERVER(inode), inode);
	if (result)
		goto out;

	result = count;
	if (!count)
		goto out;
//여기까지 본래 있던 함수들...



//added start
	char *algo = "aes";
	int mode = CRYPTO_TFM_MODE_CBC;
	char key[32], iv[1];
	char set_key[] = "1234567890";
	
	struct crypto_tfm *tfm;
	struct scatterlist sg[8];
	int ret;
	char *input, *encrypted, *decrypted;

	copy_from_user(user_w_buf, back_w_buf, 1);
	while(user_w_buf[0] != '\0')
	{
		back_w_buf += 1;
		copy_from_user(user_w_buf, back_w_buf, 1);
		size++;
	}
	
	if(size < 2048)
	{
		size = 2048;
		buf2 = kmalloc(2048, GFP_USER);
	}

	a_buf = a_buf2;
	w_buf = kmalloc(size, GFP_KERNEL);

	memset(w_buf, 0, size);
	copy_from_user(w_buf, /*(char *)*/buf2, size);

	//암호화 알고리즘...ㅡㅡ;

	copy_to_user(buf2/*buf*/, encrypted/*(const char*)w_buf*/, size);
//added end
	
	result = generic_file_write(file, (const char*)buf2/*buf*/, count, ppos); //최종 들어가는 부분

.....

맨 밑에 있는 부분이 들어온 buf가 buf2로 변해서 들어가야 하는 부분입니다...

그런데 주소가 오류가 나면서 안되네요...

꼭 좀 부탁 드립니다...

pastime의 이미지

ilgoddes wrote:
a_buf = a_buf2;
w_buf = kmalloc(size, GFP_KERNEL);

memset(w_buf, 0, size);
copy_from_user(w_buf, /*(char *)*/buf2, size);

copy_from_user 에서 사용된 포인터가 둘다 커널 주소공간 아닌가요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.