mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Re: Pending patches for MT-fork stuff
@ 2020-09-29 18:04 Jesse Hathaway
  2020-09-29 18:36 ` Rich Felker
  0 siblings, 1 reply; 11+ messages in thread
From: Jesse Hathaway @ 2020-09-29 18:04 UTC (permalink / raw)
  To: musl, Jesse Hathaway

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

I was experiencing a hang when calling setreuid from a thread on musl
1.2.1 as well as on master with these patches applied. I have attached
a Go program which hangs when run as the root user outputting only:

    main.go:31: Calling setreuid

Whereas with glibc the setreuid call completes successfully, with the
following output:

    test.go:31: Calling setreuid
    test.go:40: Running command
    test.go:45: root
    test.go:46: Command complete

I am happy to help troubleshoot the issue, yours kindly, Jesse

[-- Attachment #2: test.go --]
[-- Type: text/x-go, Size: 1574 bytes --]

package main

// #include <unistd.h>
// #include <errno.h>
import "C"

import (
	"log"
	"os"
	"os/exec"
	"os/signal"
	"os/user"
	"strconv"
	"syscall"

	"golang.org/x/sys/unix"
)

func runAsRoot() {
	cmd := exec.Command("whoami")
	uid := 0
	unprivUser := "nobody"
	lu, err := user.Lookup(unprivUser)
	if err != nil {
		log.Fatalf("Error: Unable to lookup user '%s': %v", unprivUser, err)
	}
	unprivUid, err := strconv.Atoi(lu.Uid)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}
	log.Printf("Calling setreuid")
	ret, errno := C.setreuid(C.uid_t(unprivUid), C.uid_t(uid))
	if ret != 0 {
		log.Fatalf("Error: returned %d, errno: %v", ret, errno)
	}
	euid := unix.Geteuid()
	if euid != uid {
		log.Fatalf("Error: euid %d, should be %d", euid, uid)
	}
	log.Printf("Running command")
	stdoutStderr, err := cmd.CombinedOutput()
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("%s", stdoutStderr)
	log.Printf("Command complete")
	return
}

func main() {
	log.SetFlags(log.Lshortfile)
	unprivUser := "nobody"
	lu, err := user.Lookup(unprivUser)
	if err != nil {
		log.Fatalf("Error: Unable to lookup user '%s': %v", unprivUser, err)
	}
	uid, err := strconv.Atoi(lu.Uid)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}
	ret, errno := C.setreuid(C.uid_t(0), C.uid_t(uid))
	if ret != 0 {
		log.Fatalf("Error: returned %d, errno: %v", ret, errno)
	}
	euid := unix.Geteuid()
	if euid != uid {
		log.Fatalf("Error: euid %d, should be %d", euid, uid)
	}

	go func() {
		runAsRoot()
	}()

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
	<-sigs
}

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [musl] Re: Pending patches for MT-fork stuff
@ 2020-09-29 17:19 Jesse Hathaway
  0 siblings, 0 replies; 11+ messages in thread
From: Jesse Hathaway @ 2020-09-29 17:19 UTC (permalink / raw)
  To: musl; +Cc: Jesse Hathaway

[-- Attachment #1: Type: text/plain, Size: 516 bytes --]

I was experiencing a hang when calling setreuid from a thread on musl
1.2.1 as well
as on master with these patches applied. I have attached a Go program
which hangs
when run as the root user outputting only:

    main.go:31: Calling setreuid

Whereas with glibc the setreuid call completes successfully, with the
following output:

    test.go:31: Calling setreuid
    test.go:40: Running command
    test.go:45: root
    test.go:46: Command complete

I am happy to help troubleshoot the issue, yours kindly, Jesse

[-- Attachment #2: test.go --]
[-- Type: text/x-go, Size: 1574 bytes --]

package main

// #include <unistd.h>
// #include <errno.h>
import "C"

import (
	"log"
	"os"
	"os/exec"
	"os/signal"
	"os/user"
	"strconv"
	"syscall"

	"golang.org/x/sys/unix"
)

func runAsRoot() {
	cmd := exec.Command("whoami")
	uid := 0
	unprivUser := "nobody"
	lu, err := user.Lookup(unprivUser)
	if err != nil {
		log.Fatalf("Error: Unable to lookup user '%s': %v", unprivUser, err)
	}
	unprivUid, err := strconv.Atoi(lu.Uid)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}
	log.Printf("Calling setreuid")
	ret, errno := C.setreuid(C.uid_t(unprivUid), C.uid_t(uid))
	if ret != 0 {
		log.Fatalf("Error: returned %d, errno: %v", ret, errno)
	}
	euid := unix.Geteuid()
	if euid != uid {
		log.Fatalf("Error: euid %d, should be %d", euid, uid)
	}
	log.Printf("Running command")
	stdoutStderr, err := cmd.CombinedOutput()
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("%s", stdoutStderr)
	log.Printf("Command complete")
	return
}

func main() {
	log.SetFlags(log.Lshortfile)
	unprivUser := "nobody"
	lu, err := user.Lookup(unprivUser)
	if err != nil {
		log.Fatalf("Error: Unable to lookup user '%s': %v", unprivUser, err)
	}
	uid, err := strconv.Atoi(lu.Uid)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}
	ret, errno := C.setreuid(C.uid_t(0), C.uid_t(uid))
	if ret != 0 {
		log.Fatalf("Error: returned %d, errno: %v", ret, errno)
	}
	euid := unix.Geteuid()
	if euid != uid {
		log.Fatalf("Error: euid %d, should be %d", euid, uid)
	}

	go func() {
		runAsRoot()
	}()

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
	<-sigs
}

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-03-03 20:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 18:04 [musl] Re: Pending patches for MT-fork stuff Jesse Hathaway
2020-09-29 18:36 ` Rich Felker
2020-09-29 18:51   ` Jesse Hathaway
2020-09-29 20:34     ` Rich Felker
2020-09-30  0:10       ` Rich Felker
2020-09-30 14:46         ` Jesse Hathaway
2020-09-30 15:55           ` Rich Felker
2021-03-03 14:40             ` Jesse Hathaway
2021-03-03 14:43               ` Rich Felker
2021-03-03 20:14                 ` Jesse Hathaway
  -- strict thread matches above, loose matches on Subject: below --
2020-09-29 17:19 Jesse Hathaway

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).