shell script - Unable to run shel scrip file, permission denied
2014-04
I am having shell script file, basically a setup file for installing xilinx tools. The name of the file is xsetup
Also i checked its permission after doing this
chmod 777 xsetup
In fact the entire folder's (in which my xsetup is there )permission is like this: (file access I made read and write for every one, not shown in this screenshot )
However, I am getting errors when I am trying to execute the file:
[root@sulaptop xilinx]# sh xsetup
xsetup: line 30: ./bin/lin/xsetup: Permission denied
[root@sulaptop xilinx]# bash xsetup
xsetup: line 30: ./bin/lin/xsetup: Permission denied
[root@sulaptop xilinx]#
Why I am getting this permission error when I am already logged in as root ?. here are the content of this script:
#! /bin/sh
export PATH || exec /bin/sh "$0" $argv
# Get the path to this exec
setuploc=`dirname "$0"`
unset LANG
platform=`uname -s`
# run setup executable depending on different platform
if [ "$platform" = "Linux" ]
then
machineType=`uname -m`; # Get the machine type
if [ "$machineType" = "x86_64" ]
then
# 64 bit
if [ -f "$setuploc/bin/lin64/xsetup" ]
then
"$setuploc/bin/lin64/xsetup" $*
else
if [ -f "$setuploc/bin/lin/xsetup" ]
then
"$setuploc/bin/lin/xsetup" $*
else
echo "Product is not supported on \"$platform\" platform."
fi
fi
else
if [ -f "$setuploc/bin/lin/xsetup" ]
then
"$setuploc/bin/lin/xsetup" $*
else
echo "Product is not supported on \"$platform $machineType\" platform."
fi
fi
else
echo "Un-supported platform: $platform"
fi
Line no 30 is first
"$setuploc/bin/lin/xsetup" $*
from the bottom
Platform
Fedora 17 , 64 bit as i got one flags with lm
grep lm /proc/cpuinfo:
lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm
You've changed the permissions for /home/msz/xilinx/xsetup
. The nested script being invoked by your script is /home/msz/xilinx/bin/lin/xsetup
, however. Fix the permissions on the right file.
This is related to this question.
I have a script (fix-permissions.sh
) that fixes some file permissions:
#! /bin/bash
sudo chown -R person:group /path/
sudo chmod -R g+rw /path/
And a small c program to run this, which is setuid
ed:
#include "sys/types.h"
#include "unistd.h"
int main(){
setuid(geteuid());
return system("/path/fix-permissions.sh");
}
Directory:
-rwsr-xr-x 1 root root 7228 Feb 19 17:33 fix-permissions
-rwx--x--x 1 root root 112 Feb 19 13:38 fix-permissions.sh
If I do this, everything seems fine, and the permissions do get correctly fixed:
james $ sudo su someone-else
someone-else $ ./fix-permissions
but if I use strace, I get:
someone-else $ strace ./fix-permissions
/bin/bash: /path/fix-permissions.sh: Permission denied
It's interesting to note that I get the same permission denied error with an identical setup (permissions, c program), but a different script, even when not using strace. Is this some kind of heureustic magic behaviour in setuid that I'm uncovering?
How should I figure out what's going on?
System is Ubuntu 10.04.2 LTS, Linux 2.6.32.26-kvm-i386-20101122 #1 SMP
Linux ignores the setuid bit when running a process under strace
or similar programs.
Linux-Kernel mailing list, Re: 2.4.16 + strace 4.4 + setuid programs:
From: Manfred Spraul
Date: Thu Dec 06 2001 - 12:25:53 ESTIf you want to strace setuid things and have the setuid bit honored, you have to run strace as root with the -u option.
No, even that's not possible anymore. setuid is now always ignored if a process is ptraced, even if root is ptracing - that's the fix for the latest ptrace root exploit (2.4.1x).
which is probably talking about: