LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-26-2015, 10:48 AM   #1
debguy
Member
 
Registered: Oct 2014
Location: U.S.A.
Distribution: mixed, mostly debian slackare today
Posts: 207

Rep: Reputation: 19
login damaged if using util-linux-ng-2+ and bash-4+


login damaged if using util-linux-ng-2+ and bash-4+

I noticed /etc/profile, ~/.profile, ... was never running at tail of login after i made a "linux from scratch".

It turns out both ULNG and BASH work together to clobber argv0 to bash - thus login NEVER, even if given options, is "-/bin/sh" - "NEVER A LOGIN SHELL" and "ALWAYS sh never /bin/sh" - but we're loggin in dang it. I mean a person shouldn't have to compile and debug a program as old as login (many decades old) to simply log in !!

fixing that i found A THIRD (fourth) new problem.

login.c and shell.c course is from unix (hp,ibm,the old 5), not linux, bsd, novell, or joe's, despite many new copylefts.

some fixes so far:

--------------------
from util-linux-ng-2+

FILE: login.c:1350 (right before execvp of shell)

tbuf[0] = '-';
xstrncpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ?
p + 1 : pwd->pw_shell),
sizeof(tbuf)-1);

/*
* what that did was FORCE '-sh' as shell name, stripping any
* path which /etc/passwd requested (BAD because user cannot
* see which 'sh' is running nor maybe find where 'sh' is) but
* "-sh" might be traditional but new bash interprets
* it as "means inheirit env passed by login + ENV if exists
* becomes user's .profile"
* FIX: (note shell is taken from /etc/passwd, checked elsewhere)
*/
tbuf[0] = '-';
if( strlen(pwd->pw_shell) + 1 < MAXPATHLEN )
strcpy(tbuf + 1, pwd->pw_shell);

--------------------
now from bash-4+

FILE: shell.c:1677

static void
set_shell_name (argv0)
char *argv0;
{
/* Here's a hack. If the name of this shell is "sh", then don't do
any startup files; just try to be more like /bin/sh. */

/* REMOVE shell_name = argv0 ? base_pathname (argv0) : PROGRAM; */

/*
* a hack indeed, argv0 is (never) 0 thus argv0 is always clobbered
* to PROGRAM "sh", which is never "-sh" (ie, "-/bin/sh"
* is valid) (it PRECEEDS the '-' check is why).
* MORESO otherwise just like ULNG
* it strips path but that wrong (ie, start which 'sh'? if path
* were not stripped the /etc/passwd can specify 'sh' or /bin/sh)
* as pleased.
* FIX:
*/
if( argv0 )
shell_name = argv0;
else
shell_name = PROGRAM;

--------------------
FILE: shell.c:1125

#if defined (NON_INTERACTIVE_LOGIN_SHELLS)
if (login_shell && posixly_correct == 0)
#else
if (login_shell < 0 && posixly_correct == 0)
#endif

/*
* manpage says .profile is tried for -sh OR sh -l
* good idea lets do what manuals say we do
*/

if(login_shell != 0 && posixly_correct == 0)

/*
* note if you compiled with --enable-strict-posix-default
* your miffed above because posixly_correct == 1
* (if you run "/bin/sh --posix", posixly_correct == 0
* until AFTEr startup read - at least manpage says so)
*/

// don't see a problem?
// NON_INTERACTIVE_LOGIN_SHELLS is NOT A COMPILE DEFAULT
// and is documented as a quirk feature. moreso note
// the all of the above has ZERO to do with interactive
// interactivity (ie, assume isatty is true already before
// this code is reached - next know manpage says
// .profile is attempted for ANY login interactive or not)

----------------------------
notes

Furthermore, bash not so recently has a "compat" hack which if shell name is 'sh' then it takes ENV (which btw new ULNG passes by default). This has the effect of all users login profile becoming the content of root's ENV that agetty(1) inheirited (which is supposed to be empty). while this might empower root it'd certainly be the "wrong thing to do" about 10x over.

I saw few (new) memory bugs (did not look for all, and didnt look at PAM at all) in login.c and emailed to ULNG.

I of course 1st assumed it was my setup then had to debug a couple programs.

I continually found doing "linux from scratch" that there have been many hacks injected by (unkown) which seem simply to be there to "FRAG", to delay and frustrate, new linux users. because i can say the old login.c and shell.c may have had "so called usage bugs" but didn't need hacking simply to be used. (ie, old slackware from mid 1990's was something a young teen could install in short time)

In shell.c some vars are initialized to zero some not. Be aware there "could be" compile or runtime differences if static data is set to zero (or a core value!). as to "our" issue above you may want to insure these get a default startup value:

static int no_profile=0; /* Don't execute .profile */
static int make_login_shell=0; /* Make this shell be a `-bash' shell. */

it's true! i tried it! (tm)

Last edited by debguy; 04-26-2015 at 12:17 PM.
 
Old 04-27-2015, 05:40 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Mine CLFS with utili-linux-ng-2+ and bash-4+ works good.
 
  


Reply



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
[SOLVED] Util-Linux issue: login selected! Zimo Linux From Scratch 8 10-17-2012 10:05 AM
bash Linux login file dannyboy02 Linux - Newbie 5 06-18-2012 09:14 PM
[SOLVED] Are the programs in util-linux the same version as those in util-linux-ng? harryhaller Slackware - Installation 2 10-07-2011 09:43 AM
Util-linux update. Can't login as anyone except root rconan Fedora 0 07-28-2005 03:20 PM
At the bash prompt, how do I login to Mandrake Linux? PDASquare Linux - Newbie 2 11-20-2003 07:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:48 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