Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux.c: don't use pread64 #2048

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ AC_ARG_ENABLE([profiling],
AC_ARG_WITH([debug-verbose],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Since the _FILE_OFFSET_BITS=64 value is defined, we could remove AC_SYS_LARGEFILE from the configure.ac file now

[AS_HELP_STRING([--with-debug-verbose=[[NUM]]], [Turn on runtime debugging information])],
[if test $withval -gt 0; then
AC_DEFINE_UNQUOTED([YR_DEBUG_VERBOSITY], [$withval])
AC_DEFINE_UNQUOTED([YR_DEBUG_VERBOSITY], [$withval], [Define for verbose debugging output])
else
AC_MSG_ERROR([debug verbosity must be greater than 0])
fi])
Expand Down Expand Up @@ -379,8 +379,8 @@ AM_CONDITIONAL([USE_OPENBSD_PROC], [test x$proc_interface = xopenbsd ])
AM_CONDITIONAL([USE_MACH_PROC], [test x$proc_interface = xmach ])
AM_CONDITIONAL([USE_NO_PROC], [test x$proc_interface = xnone ])
AS_IF(
[test x$proc_interface != xnone],[AC_DEFINE([HAVE_SCAN_PROC_IMPL],[1])],
[test x$proc_interface = xnone],[AC_DEFINE([HAVE_SCAN_PROC_IMPL],[0])])
[test x$proc_interface != xnone],[AC_DEFINE([HAVE_SCAN_PROC_IMPL],[1],[Define for proc-scan])],
[test x$proc_interface = xnone],[AC_DEFINE([HAVE_SCAN_PROC_IMPL],[0],[Define for proc-scan])])

# Configure TLSH function
CFLAGS="$CFLAGS -DBUCKETS_128=1 -DCHECKSUM_1B=1"
Expand Down
8 changes: 5 additions & 3 deletions libyara/proc/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <yara/proc.h>
#include <yara/strutils.h>

#define _FILE_OFFSET_BITS 64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work, it must be defined before any include for it to have an effect.

This can be confirmed by:

  • removing the AC_SYS_LARGEFILE
  • adding a _Static_assert(sizeof(off_t) == 8);
  • compiling with -m32

the static assert fails, indicating the scanning would be invalid.

That's why i was suggesting adding a static assert, it is very easy to break the fix without realizing it.


typedef struct _YR_PROC_INFO
{
int pid;
Expand Down Expand Up @@ -249,7 +251,7 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block)
// target process VM.
if (fd == -1)
{
if (pread64(
if (pread(
proc_info->mem_fd,
(void*) context->buffer,
block->size,
Expand All @@ -265,7 +267,7 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block)
{
goto _exit;
}
if (pread64(
if (pread(
proc_info->pagemap_fd,
pagemap,
sizeof(uint64_t) * block->size / page_size,
Expand All @@ -284,7 +286,7 @@ YR_API const uint8_t* yr_process_fetch_memory_block_data(YR_MEMORY_BLOCK* block)
// swap-backed and if it differs from our mapping.
uint8_t buffer[page_size];

if (pread64(
if (pread(
proc_info->mem_fd,
buffer,
page_size,
Expand Down
Loading