Skip to contentSkip to conversation

nativesdk-intercept: Fix bad intercept chgrp/chown logic

PATCH In review Ming Liu 2 participants 4 messages Oct 23, 2024 – Oct 28, 2024

lore
Share & tools
lore

Ming Liu

author
#0 lore raw

PATCH 1/1 nativesdk-intercept: Fix bad intercept chgrp/chown logic

From: Eilís 'pidge' Ní Fhlannagáin <[email protected]>

Running either of these ends up corrupting the os.execv args.

If we run:
./scripts/nativesdk-intercept/chown -R foo:foo bar

The loop here ends up missing the conversion of foo:foo to root:root because it sees sys.argv[0] and assumes that it's the user:group argument and that we should convert that. We end up a os.execv(path, args) that have the following args:

['root:root', '-R', 'foo:foo', 'bar']

As os.execv ignores args[0], we can just populate it with sys.argv[0] and then loop through sys.argv[1:]. As both chgrp and chown would have either flags and USER[:GROUP] next, this fixes the issue.

(Backported from OE-Core rev: 2a75f647ec7696d353f4b09099d777ba53f34d36)

---
 scripts/nativesdk-intercept/chgrp | 5 ++++-
 scripts/nativesdk-intercept/chown | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
scripts/nativesdk-intercept/chgrp +4 -1
index 30cc417d3a..f8ae84b8b3 100755
@@ -14,7 +14,10 @@ real_chgrp = shutil.which('chgrp', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chgrp)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue
scripts/nativesdk-intercept/chown +4 -1
index 3914b3e384..0805ceb70a 100755
@@ -14,7 +14,10 @@ real_chown = shutil.which('chown', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chown)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue
Signature · 1 line
2.43.0
author
#1 lore raw

Hi, maintainers:

Would you please cherry pick this to kirkstone, otherwise the SDK build on kirkstone is broken.

//Ming Liu

Ming Liu <[email protected]> 於 2024年10月23日 週三 下午1:15寫道:

Quoted 70 lines

From: Eilís 'pidge' Ní Fhlannagáin <[email protected]>

Running either of these ends up corrupting the os.execv args.

If we run:
./scripts/nativesdk-intercept/chown -R foo:foo bar

The loop here ends up missing the conversion of foo:foo to root:root because
it sees sys.argv[0] and assumes that it's the user:group argument and that we
should convert that. We end up a os.execv(path, args) that have the following
args:

['root:root', '-R', 'foo:foo', 'bar']

As os.execv ignores args[0], we can just populate it with sys.argv[0] and then
loop through sys.argv[1:]. As both chgrp and chown would have either flags and
USER[:GROUP] next, this fixes the issue.

(Backported from OE-Core rev: 2a75f647ec7696d353f4b09099d777ba53f34d36)

---
 scripts/nativesdk-intercept/chgrp | 5 ++++-
 scripts/nativesdk-intercept/chown | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
scripts/nativesdk-intercept/chgrp +4 -1
index 30cc417d3a..f8ae84b8b3 100755
@@ -14,7 +14,10 @@ real_chgrp = shutil.which('chgrp', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chgrp)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue
scripts/nativesdk-intercept/chown +4 -2
index 3914b3e384..0805ceb70a 100755
@@ -14,7 +14,10 @@ real_chown = shutil.which('chown', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chown)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue
--

2.43.0

#2 lore raw
Quoted 4 lines · Ming Liu

Hi, maintainers:

Would you please cherry pick this to kirkstone, otherwise the SDK build on kirkstone is broken.

Firstly, you need to copy the maintainer for kirkstone. I've added him to the address list.

Secondly, the patch is also already in his test queue:

https://git.yoctoproject.org/poky-contrib/commit/?h=stable/kirkstone-nut&id=145886736d92a55df1e822aa75044028627587ec

Thirdly, you gave us two business days to handle this before following up :/.

Cheers,

Richard

Quoted 68 lines

Ming Liu <[email protected]> 於 2024年10月23日 週三 下午1:15寫道:

Quoted 67 lines

From: Eilís 'pidge' Ní Fhlannagáin <[email protected]>

Running either of these ends up corrupting the os.execv args.

If we run:
./scripts/nativesdk-intercept/chown -R foo:foo bar

The loop here ends up missing the conversion of foo:foo to root:root because
it sees sys.argv[0] and assumes that it's the user:group argument and that we
should convert that. We end up a os.execv(path, args) that have the following
args:

['root:root', '-R', 'foo:foo', 'bar']

As os.execv ignores args[0], we can just populate it with sys.argv[0] and then
loop through sys.argv[1:]. As both chgrp and chown would have either flags and
USER[:GROUP] next, this fixes the issue.

(Backported from OE-Core rev:
2a75f647ec7696d353f4b09099d777ba53f34d36)

---
 scripts/nativesdk-intercept/chgrp | 5 ++++-
 scripts/nativesdk-intercept/chown | 5 ++++-

 2 files changed, 8 insertions(+), 2 deletions(-)
scripts/nativesdk- renamed from scripts/nativesdk-intercept/chgrp +0 -0

intercept/chgrp
index 30cc417d3a..f8ae84b8b3 100755

scripts/nativesdk-intercept/chgrp +0 -0
@@ -14,7 +14,10 @@ real_chgrp = shutil.which('chgrp', path=path)
  args = list()
 

 found = False

scripts/nativesdk-intercept/chgrp +4 -1
-for i in sys.argv:
+
+args.append(real_chgrp)
+
+for i in sys.argv[1:]:

     if i.startswith("-"):
         args.append(i)
         continue

scripts/nativesdk- renamed from scripts/nativesdk-intercept/chown +0 -0

intercept/chown
index 3914b3e384..0805ceb70a 100755

scripts/nativesdk-intercept/chown +0 -0
@@ -14,7 +14,10 @@ real_chown = shutil.which('chown', path=path)
  args = list()
 

 found = False

scripts/nativesdk-intercept/chown +4 -1
-for i in sys.argv:
+
+args.append(real_chown)
+
+for i in sys.argv[1:]:

     if i.startswith("-"):
         args.append(i)
         continue

author
#3 lore raw

Hi, Richard:

Thanks for the info, will add maintainer of the LTS branches to the mail list next time.

the best,
thank you

Richard Purdie <[email protected]> 於 2024年10月28日 週一 上午10:44寫道:

Quoted 92 lines · Ming Liu
Quoted 4 lines

Hi, maintainers:

Would you please cherry pick this to kirkstone, otherwise the SDK build on kirkstone is broken.

Firstly, you need to copy the maintainer for kirkstone. I've added him to the address list.

Secondly, the patch is also already in his test queue:

https://git.yoctoproject.org/poky-contrib/commit/?h=stable/kirkstone-nut&id=145886736d92a55df1e822aa75044028627587ec

Thirdly, you gave us two business days to handle this before following up :/.

Cheers,

Richard

Quoted 68 lines

Ming Liu <[email protected]> 於 2024年10月23日 週三 下午1:15寫道:

Quoted 67 lines

From: Eilís 'pidge' Ní Fhlannagáin <[email protected]>

Running either of these ends up corrupting the os.execv args.

If we run:
./scripts/nativesdk-intercept/chown -R foo:foo bar

The loop here ends up missing the conversion of foo:foo to root:root because
it sees sys.argv[0] and assumes that it's the user:group argument and that we
should convert that. We end up a os.execv(path, args) that have the following
args:

['root:root', '-R', 'foo:foo', 'bar']

As os.execv ignores args[0], we can just populate it with sys.argv[0] and then
loop through sys.argv[1:]. As both chgrp and chown would have either flags and
USER[:GROUP] next, this fixes the issue.

(Backported from OE-Core rev:
2a75f647ec7696d353f4b09099d777ba53f34d36)

---
 scripts/nativesdk-intercept/chgrp | 5 ++++-
 scripts/nativesdk-intercept/chown | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
scripts/nativesdk- renamed from scripts/nativesdk-intercept/chgrp +0 -0

intercept/chgrp
index 30cc417d3a..f8ae84b8b3 100755

scripts/nativesdk-intercept/chgrp +4 -1
@@ -14,7 +14,10 @@ real_chgrp = shutil.which('chgrp', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chgrp)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue
scripts/nativesdk- renamed from scripts/nativesdk-intercept/chown +0 -0

intercept/chown
index 3914b3e384..0805ceb70a 100755

scripts/nativesdk-intercept/chown +4 -1
@@ -14,7 +14,10 @@ real_chown = shutil.which('chown', path=path)
 args = list()
 
 found = False
-for i in sys.argv:
+
+args.append(real_chown)
+
+for i in sys.argv[1:]:
     if i.startswith("-"):
         args.append(i)
         continue