public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Kristian Sørensen" <ks@cs.aau.dk>
To: linux-kernel@vger.kernel.org
Subject: Reading large /proc entry from kernel module
Date: Tue, 8 Mar 2005 14:45:56 +0100	[thread overview]
Message-ID: <200503081445.56237.ks@cs.aau.dk> (raw)

Hi all!

I have some trouble reading a 2346 byte /proc entry from our Umbrella kernel 
module.

Proc file is created write-only and I am able to write text to the file, and 
read it from kernel space. The function reading the entry is in short this:

static int umb_proc_write(struct file *file, const char *buffer,
                          unsigned long count, void *data) {
	char *policy;
	int *lbuf;
	int i;
	
	if (count != UMB_POLICY_SIZE) {
		printk("Umbrella: Error - /proc/umbrella is of invalid size\n");
		return -EFAULT;
	}

	/* Initialization of lbuf */
	policy = kmalloc(sizeof(char)*UMB_POLICY_SIZE, GFP_ATOMIC);
	lbuf = kmalloc(count, GFP_KERNEL);
	if (!lbuf || !policy) {
		kfree(lbuf);
		kfree(policy);
		return -EFAULT;
	}
	if (copy_from_user(lbuf, buffer, count)) {
		kfree(lbuf);
		kfree(policy);
		return -EFAULT;
	}

	strcpy(policy, lbuf);
	umb_parse_proc(policy);

}


If I read byte by byte will only give the characters on every fourth index. 
E.g. reading lbuf with the string "abcd", then lbuf[0]==a and lbuf[1]==d ...
- Do anyone have an explanation for this behaviour? Making the strcpy does fix  
the problem - and the complete string is available! :-/ ...

Now that everything works, I want to write a string of excactly 2346 
characters to the /proc/umbrella file. However when I make the 
copy_from_user, I only get the first 1003 characters :-((
- Do you have a pointer to where I do this thing wrong?

What is the limit regarding the size of writing a /proc entry? (we consider 
importing binary public keys to the kernel this way in the future).


Best regards,
Kristian.

-- 
Kristian Sørensen
- The Umbrella Project  --  Security for Consumer Electronics
  http://umbrella.sourceforge.net

E-mail: ipqw@users.sf.net, Phone: +45 29723816

             reply	other threads:[~2005-03-08 13:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-08 13:45 Kristian Sørensen [this message]
2005-03-08 23:04 ` Reading large /proc entry from kernel module Peter Chubb
2005-03-08 23:31   ` Kristian Sørensen
2005-03-09 15:17 ` Bob Bennett
2005-03-09 21:59   ` Kristian Sørensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200503081445.56237.ks@cs.aau.dk \
    --to=ks@cs.aau.dk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox