Qualcomm Interview Question for Software Engineer / Developers


Country: United States




Comment hidden because of low score. Click to expand.
2
of 2 vote

one of the major requirement in system call implementation is to check the validity of user parameter pointer passed as argument, kernel should not blindly follow the user pointer as the user pointer can play tricks in many ways. Major concerns are: 1. it should be a pointer from that process address space - so that it cant get into some other process address space. 2. it should be a pointer from user space - it should not trick to play with a kernel space pointer. 3. it should not bypass memory access restrictions.

that is why copy_from_user() is performed. It is blocking and process sleeps until page fault handler can bring the page from swap file to physical memory.

- ritesh ghosh May 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

copy_from_user does not page fault unlike other kernel or user code sections when an attempt happens to access memory addresses passed by userspace. This allows it to gracefully handle exception instead of kernel panic.

- Brave Heart March 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

copy_from_user() is usually used when writing certain device drivers. Note that there is no "mapping" of bytes here, the only thing that is happening is the copying of bytes from a certain virtual location mapped in user-space to bytes in a location in kernel-space. This is done to enforce separation of kernel and user and to prevent any security flaws -- you never want the kernel to start accessing and reading arbitrary user memory locations or vice-versa. That is why arguments and results from syscalls are copied to/from the user before they actually run.
h-t-t-p://stackoverflow.com/questions/12925339/the-implementation-of-copy-from-user

- sivasrinivas March 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

If kernel directly accesses the user data structure, system will panic if it's not a valid address( eg NULL pointer). To avoid this situation, copy_from_user(..) is used. This function will fail, if proper user address is not provided and does not bring down the system.

- Pradeep August 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

User memory is untrusted.

It is possible that a thread doing a syscall will get scheduled out after validating the user memory but before actually completing the syscall. A different process thread might now replace the user memory with a different one, invalidating the memory. (Or if it is a multiprocessor machine...)

In order to be secure/correct, trying to validate the memory on each switch is pointless. In fact, should we allow the memory to change? Making a copy first is better in terms of security and (eventual) performance etc.

- Anonymous December 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Also a memcopy may not work for all the architectures.

Also the user may pass something junk, so some sanity check on the address .. etc

what do you guys say

- bandwidth January 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

One correction :) When a process gets scheduled out just before completing copy_from_user() and then gets scheduled back in, at that point the address space doesn't belong to last process that ran on that CPU. It actually belongs to the process that was scheduled out. This is because during a process switch, CR3 register (on x86 and AMD64) is restored. This register points to page global directory, the top level page table. Hence full address space of the process being switched-in is restored. So copy_from_user() will resume normally.

- sindhi February 05, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

copy_from_user() is required because, user memory page can be swapped. This will create the problem if user memory is provided to DMA of some device driver.
If kernel provided the user memory to device driver and called scheduler. Scheduler might schedule new task which can swap out the page containing the user memory given to device driver. If the device driver DMA starts at this moment, then it will read the wrong data.

- Ajay April 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think, the following article also summarises well whatever many of you are trying to explain.

h-t-t-p://linuxforthenew.blogspot.in/2013/01/why-doshould-we-use-copyfromuser-or.html

- tvbgeek October 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

swap, swap, swap

- Anonymous August 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hot girls at HDAsianPics_com

- HDAsianPics.com October 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hot girls at HDAsianPics_com

- HDAsianPics October 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

HDAsianPicsDotCom

- HDAsianPics October 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

HDAsianPics

- HDAsianPics October 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hot girls

- HDAsianPics October 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

- Anonymous November 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

plz tell the output of this

- wasi December 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why don't you run it yourself?

- Anonymous December 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

how is this program related to original question in this thread?

- bvgr December 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Answer would be ==> 33 25 20 13 10 1

- srinivas January 04, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More