LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2015, 05:03 AM   #31
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513

Quote:
Originally Posted by mina86 View Post
You cannot mmap for writing a running executable. Same as you cannot open it for writing.
Wasn't meaning it would be the executable. It would be a data file.
 
Old 06-15-2015, 06:09 AM   #32
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
Originally Posted by jpollard View Post
Wasn't meaning it would be the executable. It would be a data file.
Yes, having a separate per-user configuration file would solve ETXTBSY problem, but mmap still won’t solve synchronisation so it doesn’t really matter if the file is mmaped or simply opened with (f)open – to synchronise access flock would have to be used anyway.
 
Old 06-15-2015, 07:48 AM   #33
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by mina86 View Post
Yes, having a separate per-user configuration file would solve ETXTBSY problem, but mmap still wont solve synchronisation so it doesnt really matter if the file is mmaped or simply opened with (f)open to synchronise access flock would have to be used anyway.
Yes. But at least it would work for more than just the owner of the executable (and the directory the executable is in). It would also eliminate the complaint about having to parse the file...

BTW, What the op is doing is the way a virus would have to work...

Last edited by jpollard; 06-15-2015 at 08:10 AM.
 
Old 06-16-2015, 04:22 AM   #34
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Original Poster
Rep: Reputation: 22
Quote:
Originally Posted by jpollard View Post
Yes. But at least it would work for more than just the owner of the executable (and the directory the executable is in). It would also eliminate the complaint about having to parse the file...

BTW, What the op is doing is the way a virus would have to work...
I got into this with just an innocent query in my mind, "Could this work?" I had a couple bytes of state data and I wanted to avoid writing a config file and all the parse code for it.

Very quickly I realized this could have evil intent. Look at how so many Linux users nowadays just blindly install the binary packages from their favorite distro. These programs could be doing anything besides what they claim to be doing. This is certainly how to spread virus in linux: infect a whole distro from 1 innocent looking utility/lib upgrade. The code to make this happen is tiny, and could easily be hidden in the source with a couple funny looking macros. Someone would need to look very close to find it.

There's a lot of naivete in the Linux community. This bothers me, and SELinux is not the answer.

As a closely related sidenote: I recently got a new desktop PC and proceeded to install fresh Linux on it, which I have not done in about 10 years. After about 10 or 12 different distros, I find myself actually writing my own /sbin/init so I can bypass systemd and all that bloat. I have a fully working system with X and WM that takes <30 seconds from reboot to login, and most of that is BIOS/POST. I'll probably end up using systemd, just because everything expects systemd, but I don't trust systemd. It's all opaque binaries, no sysvinit shell scripts anymore. Now nobody knows what the heck is going on. What happened to Linux in 10 years?

BTW, if your initrd works properly, here's a drop in replacement for /sbin/init(systemd):
Code:
#!/bin/sh
mount -0 rw,remount /
hostname `cat /etc/hostname`
while [ 1 ]; do
    /sbin/agetty tty1 linux
done
Now THAT reminds me of Linux
 
Old 06-16-2015, 05:48 AM   #35
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by mdooligan View Post
I got into this with just an innocent query in my mind, "Could this work?" I had a couple bytes of state data and I wanted to avoid writing a config file and all the parse code for it.

Very quickly I realized this could have evil intent. Look at how so many Linux users nowadays just blindly install the binary packages from their favorite distro. These programs could be doing anything besides what they claim to be doing. This is certainly how to spread virus in linux: infect a whole distro from 1 innocent looking utility/lib upgrade. The code to make this happen is tiny, and could easily be hidden in the source with a couple funny looking macros. Someone would need to look very close to find it.
Actually, this is blocked by even the simple things.

First, as the OP found, you can't modify a running executable.
Second, you have to copy the file before modifying it - thus, the copy of the file will be owned by the user running it.
Third, the file cannot be put back in the original place UNLESS the owner of the original file is the same as the user running it or have group write access to the directory containing the file...

Finally, SELinux can block all three.

The result is that the modified executable will not have the same owner, or security flags unless the user running the binary ALREADY owns the executable AND has the same security flags...

Quote:

There's a lot of naivete in the Linux community. This bothers me, and SELinux is not the answer.

As a closely related sidenote: I recently got a new desktop PC and proceeded to install fresh Linux on it, which I have not done in about 10 years. After about 10 or 12 different distros, I find myself actually writing my own /sbin/init so I can bypass systemd and all that bloat. I have a fully working system with X and WM that takes <30 seconds from reboot to login, and most of that is BIOS/POST. I'll probably end up using systemd, just because everything expects systemd, but I don't trust systemd. It's all opaque binaries, no sysvinit shell scripts anymore. Now nobody knows what the heck is going on. What happened to Linux in 10 years?

BTW, if your initrd works properly, here's a drop in replacement for /sbin/init(systemd):
Code:
#!/bin/sh
mount -0 rw,remount /
hostname `cat /etc/hostname`
while [ 1 ]; do
    /sbin/agetty tty1 linux
done
Now THAT reminds me of Linux
That only works for a single user mode. No network, no services...

If your base system uses systemd, then the way systemd has wormed its way into the system (currently, it starts in the initrd), it won't work either. agetty is now needed to login - guess what? You can't login as the needed systemd services to login aren't there. You have to replace "login" with one that doesn't depend on systemd (or at least replace the PAM modules that do...).

If you try to start the network.... it will also fail, unless you replace the various tools tied to systemd. You could manually start the network with ifconfig... But most of the services you would want to provide requires systemd...

If you want a system that works the traditional way, look at Slackware. So far, it has avoided systemd, partly by forking the projects that have been taken over by systemd, and partly by just being rather sane about it.

And as you say, it boots in under 30 seconds (my last check it was like 25 and that was using a VM; it would be faster with bare metal instead).
 
Old 06-16-2015, 07:31 AM   #36
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
you don't have to use systemd
and probably never will
 
Old 06-16-2015, 08:27 AM   #37
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by genss View Post
you don't have to use systemd
and probably never will
wish.

Nearly every desktop distribution (and a number of server versions) have switched to using systemd. Even some embedded systems use it.
 
Old 06-16-2015, 09:31 AM   #38
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
wish.

Nearly every desktop distribution (and a number of server versions) have switched to using systemd. Even some embedded systems use it.
whatever
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find me source code for "iwlist" & "iwconfig" Angela Wu Linux - Kernel 2 09-15-2013 08:44 PM
Facing error while running "g++ 3.4.4" code in "g++ 4.3.3" Suranjit Ubuntu 2 10-08-2009 11:22 PM
Emulate "dup2()" without using "fcntl()" bit128_linux Linux - General 0 03-12-2008 11:12 AM
Emulate keyboard key "left" Ephracis Linux - Software 1 05-22-2005 08:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration