PackageKit: tweak classes used by packagefs to write to user buffers.

when compiled in kernel mode, BMemoryIO::WriteAt() and BBufferDataReader::ReadData()
now check the buffer to write to, and eventually call user_memcpy() instead of memcpy().
This commit is contained in:
Jérôme Duval 2018-01-08 20:59:32 +01:00
parent 51051c56d3
commit 8c44fc0f65
2 changed files with 20 additions and 0 deletions

View File

@ -10,6 +10,10 @@
#include <string.h>
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
#include <arch/user_memory.h>
#endif
namespace BPackageKit {
@ -63,6 +67,12 @@ BBufferDataReader::ReadData(off_t offset, void* buffer, size_t size)
if (size > fSize || offset > (off_t)fSize - (off_t)size)
return B_ERROR;
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
if (IS_USER_ADDRESS(buffer)) {
if (user_memcpy(buffer, (const uint8*)fData + offset, size) != B_OK)
return B_BAD_ADDRESS;
} else
#endif
memcpy(buffer, (const uint8*)fData + offset, size);
return B_OK;
}

View File

@ -15,6 +15,10 @@
#include <Errors.h>
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
#include <arch/user_memory.h>
#endif
BDataIO::BDataIO()
{
@ -366,6 +370,12 @@ BMemoryIO::WriteAt(off_t pos, const void* buffer, size_t size)
ssize_t sizeWritten = 0;
if (pos < (off_t)fBufferSize) {
sizeWritten = min_c((off_t)size, (off_t)fBufferSize - pos);
#if defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
if (IS_USER_ADDRESS(fBuffer)) {
if (user_memcpy(fBuffer + pos, buffer, sizeWritten) != B_OK)
return B_BAD_ADDRESS;
} else
#endif
memcpy(fBuffer + pos, buffer, sizeWritten);
}