0

In my kernel module the read function is as follows:

ssize_t aes_read(struct file *filp, char *buf, size_t count, loff_t *f_pos) { 

  unsigned long aes_reg[4];
  aes_reg[0] = leon_load_reg(output_mem_loc);
  aes_reg[1] = leon_load_reg(output_mem_loc+4);
  aes_reg[2] = leon_load_reg(output_mem_loc+8);
  aes_reg[3] = leon_load_reg(output_mem_loc+12);
  copy_to_user(buf, (char *)aes_reg, 16);
  ....

And it appears in the kernel module that buf is being set properly. On the user space side I have written this:

int main(int argc, char* argv[]){
    FILE *fpaes;
    char *str;
    int buf[4];

    fpaes = fopen("/dev/aes", "r");
    fread(str, 16, 1, fpaes);
    p_long = (unsigned long *)str;
    ....

But str is not being updated with the values I expect. Am I allowed to do an fread in this way or am I way off?

1
  • 1
    This isn't causing your problem, but not that it's generally preferable to directly call the system calls read(2) et al instead of going through the stdio layer, since stdio buffers reads and writes by default. Commented Aug 23, 2012 at 18:50

1 Answer 1

3

str is not initialized in your program. Accessing *str is undefined behavior.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, I must have missed that. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.