Skip to content

Conversation

@kateinoigakukun
Copy link

To make it work with glibc 2.35 shipped with Ubuntu jammy

To make it work with glibc 2.35 shipped with Ubuntu jammy
@echoix
Copy link

echoix commented Apr 9, 2024

I tried your changes (plus mine that ported this project to python 3), on a project I wanted to debug the makefiles, and it also failed with a unrecognised symlinkat syscall (decimal 266, hex 0x10A). It has the second argument as an integer as a file handle. I wasn't quite sure what the contents of the function to point at should be yet, do you have an idea?

@kateinoigakukun
Copy link
Author

kateinoigakukun commented Apr 9, 2024

@echoix I pushed a new commit to support symlinkat(2) :)

Note that I just tested a simple program, not tested seriously.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int main() {
    int fd;
    char *path = "test.txt";
    char *symlink_path = "test_symlink.txt";

    // Create a file
    fd = open(path, O_CREAT | O_RDWR, 0644);
    if (fd == -1) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    close(fd);

    // Create a symbolic link
    if (symlinkat(path, AT_FDCWD, symlink_path) == -1) {
        perror("symlinkat");
        exit(EXIT_FAILURE);
    }

    printf("Symbolic link created successfully.\n");

    return 0;
}

@echoix
Copy link

echoix commented Apr 9, 2024

I'll check what it looks like this weekend. I don't know if this tool will help me at all yet, but I hope so

@echoix
Copy link

echoix commented Apr 9, 2024

It got a bit further :)
But there's an error now

make[3]: Entering directory '/workspace/mkcheck/grass/include/grass'
/usr/bin/install -c -m 644 version.h /workspace/mkcheck/grass/dist.x86_64-pc-linux-gnu/include/grass/version.h
../../config.status --config | sed "s/'//g" | sed 's/\(.*\)/".\/configure \1"/' > /workspace/mkcheck/grass/dist.x86_64-pc-linux-gnu/include/grass/confparms.h
[Exception] Exception while handling syscall 266 in process 108 (/usr/bin/ln): Cannot read from child memory (errno = 14)

and running again without cleaning this time:

(cd /workspace/mkcheck/grass/dist.x86_64-pc-linux-gnu/lib; ln -f -s libgrass_datetime.8.4.so /workspace/mkcheck/grass/dist.x86_64-pc-linux-gnu/lib/libgrass_datetime.so)
[Exception] Exception while handling syscall 266 in process 226 (/usr/bin/ln): Cannot read from child memory (errno = 14)

The error message is from

mkcheck/mkcheck/util.cpp

Lines 40 to 72 in ea826e3

// -----------------------------------------------------------------------------
std::string ReadString(pid_t pid, uint64_t addr, size_t len)
{
std::string result;
char buffer[kPageSize];
uint64_t read = 0;
for (size_t i = 0; i < len; ++i) {
const uint64_t end = (addr + kPageSize) & (kPageSize - 1);
const uint64_t len = kPageSize - end;
ssize_t count = ReadBuffer(pid, buffer, addr, len);
if (count < 0) {
throw std::runtime_error(
"Cannot read from child memory (errno = " +
std::to_string(errno) +
")"
);
}
for (size_t i = 0; i < count; ++i) {
if (buffer[i] == '\0') {
result.append(buffer, i);
return result;
}
}
result.append(buffer, count);
addr += count;
}
return result;
}

At first my make had multiple jobs (-j$(nproc)), but I started again without that to avoid some types of issues.

I'm trying to connect a debugger to see whats going on now

@echoix
Copy link

echoix commented Apr 10, 2024

Ok, what's weird is that the first errors I encountered was with the existing sys_symlink syscall.

But in the meantime, in my fork, I adapted the project to be able to compile with gcc (at least for gcc 11 and gcc 12). It is simply that the table with the syscall hooks need to be ordered, and without blanks. I filled a lot of them with SYS_ constants (pointing at sys_ignore function pointer), but at a point it was becoming long, so I just repeated the hex in the squared brackets so I could batch create the missing ones.

Unfortunately (but expectedly), it created the same errors. So it's not from the new function sys_symlinkat. When I added a breakpoint just before the throw, the buffer read way past the \0 of the file name of the argument. It's kinda weird that it didn't stop, and I was seeing the two paths in the same variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants