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

cpm aborts on start with: "Failed to scan kernel release". #35

Closed
ssm opened this issue Jun 20, 2013 · 2 comments
Closed

cpm aborts on start with: "Failed to scan kernel release". #35

ssm opened this issue Jun 20, 2013 · 2 comments

Comments

@ssm
Copy link
Collaborator

ssm commented Jun 20, 2013

cpm is unhappy with my kernel…

$ cpm
Failed to scan kernel release. (Success, 0)
Can't attach to parent!
[1] 23628 killed cpm
$ echo $?
137

$ uname -a
Linux turbotape 3.10-rc5-amd64 #1 SMP Debian 3.10rc5-1exp1 (2013-06-11) x86_64 GNU/Linux

$dpkg -l cpm
[...] cpm 0.28-1 [...]

@comotion
Copy link
Owner

that's a scary kernel release.
two things are happening here, both of them pertaining to security.c:

  • check_kernel_version() is called to decide if user can mlock (>=2.6.9)
    this fails but it's due to sscanf expecting major, minor and point release in your kernel version. You seem to only have 3.10-rcX, so maybe there's the rub.
int check_kernel_version()
{        
  struct utsname uts;
  if(uname(&uts) == -1){
    fprintf(stderr, "%s (%s, %d)\n",
            _("Failed to discover kernel version."),
            strerror(errno), errno);
  }else if(!strncmp(uts.sysname, "Linux", 5)){
    int maj,min,rel;
    if(sscanf(uts.release, "%d.%d.%d", &maj, &min, &rel) != 3) {                                                                            
      fprintf(stderr, "%s (%s, %d)\n",
              _("Failed to scan kernel release."),
              strerror(errno),errno);
    }else{
      //fprintf(stdout, "kernel rel: %d.%d\n", maj, min);
      if(maj > 2 ||
        (maj == 2 && min > 6) ||
        (maj == 2 && min == 6 && rel >= 9))
        return 1;
    }    
  }      
  return 0;
}
  • CPM tries to ptrace attach to itself to avoid getting debugged for secrets, and fails, which causes it to shoot itself in the head. This needs some investigation: can you try a snippet of code for me that just tries to attach itself?
#include <stdio.h>                                                                                                                                
#include <stdlib.h>
#include <errno.h>
#include <sys/utsname.h>
#include <sys/prctl.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{       
   int status;
   pid_t p, p0 = getpid();
   p = fork();
   if (p == -1) {
      fprintf(stderr, "Could not fork: %s\n", strerror(errno));
      _exit(1);
   }    

   if (p == 0) {
      if (prctl(PR_SET_DUMPABLE, 0, 0, 0, 0) != 0) {
         fprintf(stderr, "Can not set child non dumpable\n");
         _exit(1);
      } 
      if (ptrace(PT_ATTACH, p0, 0, 0) != 0) {
         // someone is already attached to us; shoot the parent in the head
         fprintf(stderr, "Can't attach to parent!\n");
         perror("foobar");
         kill(p0, SIGKILL);
         _exit(1);
      } 
      printf("Attached to %d\n", p0);
      while (1) {
         if(ptrace(PT_SYSCALL, p0, 0, 0) == 0)
            waitpid(p0, &status, 0);
         if(errno == ESRCH && kill(p0, 0) == -1)
            exit(0); // parent is dead

      } 
      _exit(0);
   }else { //twiddle thumbs
      fprintf(stderr, "forked %d from %d\n", p, p0);
      while(1){
         sleep(1); // ZzzZZzZZ
      } 
   }    

}

@comotion
Copy link
Owner

this should be fixed in 8c23b2e

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

No branches or pull requests

2 participants