Skip to contentSkip to conversation

The disappearing sys_call_table export.

DISCUSSION Chuck Ebbert 3 participants 3 messages May 11, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · arjanv

examle: pseudocode for the unlink syscall

long your_wrapped_syscall(char *userfilename)

{
    char kernelpointer[something];
    copy_from_user(kernelpointer, usefilename, ...);
    audit_log(kernelpointer);
    return original_syscall(userfilename);
}

That code has another hole that nobody else has mentioned
yet: I can fill the audit log by trying to delete nonexistent files, and if accused of trying to mount a DOS attack on the audit trail I can reasonably claim that it was all an accident...

How about:

long wrapped_unlink(char *userfilename)

{
        char name1[len], name2[len];
        long ret;

        copy_from_user(name1, userfilename, ...);
        ret = original_unlink(userfilename);
        copy_from_user(name2, userfilename, ...);

        if (strncmp(name1, name2, len))
                audit_log(name1, name2, UNLINK_NAME_CHANGED);
        if (ret == 0 && AUDIT_SUCCESS)
                audit_log(name1, name2, UNLINK_SUCCEEDED);
        if (ret == -EPERM && AUDIT_FAILURE)
                audit_log(name1, name2, UNLINK_FAILED);

        return ret;
}
#1 lore raw
Quoted 1 line · Chuck Ebbert

How about:

Here's a good rule of thumb:
In security, if you need to ask, it's probably broken.

The way to do security design is NOT by throwing a few kludgy hacks against the wall and seeing if any of them stick. That's a recipe for security holes. The way you get security right is by building a clean, simple design that you can convincingly argue to be correct. In security, you don't write code until you've got your assurance argument down pat.

If you can't convince yourself it's correct, it's probably not.

Quoted 3 lines
       copy_from_user(name1, userfilename, ...);
       ret = original_unlink(userfilename);
       copy_from_user(name2, userfilename, ...);

Insecure. Simply exploit the race condition twice: once just before the original_unlink() to change the string to a dangerous filename, then a second time just after the original_unlink() to change it back.

#2 lore raw
In reply to Chuck Ebbert
Quoted 4 lines · Chuck Ebbert

That code has another hole that nobody else has mentioned
yet: I can fill the audit log by trying to delete nonexistent files, and if accused of trying to mount a DOS attack on the audit trail I can reasonably claim that it was all an accident...

No one specified what audit_log does in this case. Usually, in such modules, the audit function doesn't just log everything. It can, for example, rate-limit the logging and just spit a message about the user DoSing the log system. If system is paranoid enough to be fail-closed (i.e. fears that the user is hitting the rate-limit of the logger, hoping to cover his real acts), it can always kill his task, kill all his processes, lock his account, call the authorities, etc. Its up to the system to decide what audit_log does, just like in any other auditing system.

Quoted 4 lines

How about:

long wrapped_unlink(char *userfilename)

Quoted 10 lines
{
        char name1[len], name2[len];
        long ret;

        copy_from_user(name1, userfilename, ...);
        ret = original_unlink(userfilename);
        copy_from_user(name2, userfilename, ...);

        if (strncmp(name1, name2, len))
                audit_log(name1, name2, UNLINK_NAME_CHANGED);

Still subject to a timing attack. The usermode code can change it and change it back as soon as the file has been unlinked. If the system is under heavy load (generated by the attacker), the attacking process is reniced to 20, and the monitoring part of it has higher priority and keeps stat(2)ing the file, a thread in the attack code may actually be able to change the filename back in time for the second check.

The only way to avoid these races is to have just one copy, by either using set_fs (see my previous post in this thread) or by hooking inside the syscall (as LSM does).

Yoav Weiss