ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: ALT Linux Team development discussions <devel@lists.altlinux.org>
Subject: Re: [devel] suid binaries and ELF Auxiliary Vectors
Date: Fri, 25 Sep 2009 13:05:38 +0300
Message-ID: <cc557aab0909250305i5f4a5f01hb1dfeac1bc782858@mail.gmail.com> (raw)
In-Reply-To: <20090925092402.GA5880@newmaster.mivlgu.local>

2009/9/25 Sergey Vlasov <vsu@altlinux.ru>:
> On Fri, Sep 25, 2009 at 10:38:50AM +0300, Kirill A. Shutemov wrote:
>> Может кто-нибудь подскажет, почему suid'ый бинарник получает пустой
>> auxv?
>
> На самом деле он получает непустой auxv, однако используемый для поиска
> auxv код в этих условиях не работает.
>
>> Маленький testcase:
>>
>> #include <elf.h>
>> #include <stdio.h>
>> #include <unistd.h>
>>
>> int main(int argc, char **argv, char **envp)
>> {
>>         Elf32_auxv_t *auxv;
>>         while(*envp++ != NULL);
>>
>>         for (auxv = (Elf32_auxv_t *)envp; auxv->a_type != AT_NULL; auxv++)
>>                 printf("%d: 0x%08x\n", auxv->a_type, auxv->a_un.a_val);
>>
>>         printf("uid: %d\n", geteuid());
>>
>>         return 0;
>> }
>>
>> Для x86_64, его нужно немного поправить.
>>
>> Если у исполняемого файла нет suid-бита(или owner == uid), то auxv
>> печатается нормально иначе получаем только uid. Есть идеи почему?
>> И где код кторый это делает?
>
> glibc/elf/rtld.c:process_envvars() при запуске программы с повышенными
> привилегиями (с установленным флагом __libc_enable_secure) удаляет
> некоторые переменные окружения вызовом unsetenv(), в результате чего
> простым поиском NULL в envp не удаётся найти начало auxv.  Можно
> попробовать запустить SUID-программу с очищенным окружением (через
> "env -", или явно убрав только мешающие переменные) - в этом случае
> поиск auxv проходит даже при наличии SUID.  Обычно мешают как минимум
> переменные PWD и TMPDIR.
>
> Если предположить, что auxv не может быть пустым, и используется
> текущая реализация unsetenv() из glibc/elf/dl-environ.c (где хвост
> envp гарантированно заполняется NULL даже в случае, когда одновременно
> удаляется несколько переменных с одинаковым именем), работает
> следующий hackaround:
>
>        while(*envp++ != NULL);
> +       while (*envp == NULL) ++envp;
>
> (добавляется пропуск лишних NULL).

Спасибо!

  reply	other threads:[~2009-09-25 10:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-25  7:38 Kirill A. Shutemov
2009-09-25  8:15   ` Kirill A. Shutemov
2009-09-25  8:23     ` Kirill A. Shutemov
2009-09-25  9:12       ` Dmitry V. Levin
2009-09-25  9:24 ` Sergey Vlasov
2009-09-25 10:05   ` Kirill A. Shutemov [this message]
2009-09-25 10:20   ` Kirill A. Shutemov
2009-09-25  9:29 ` Andrey Rahmatullin
2009-09-25  9:35   ` Dmitry V. Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc557aab0909250305i5f4a5f01hb1dfeac1bc782858@mail.gmail.com \
    --to=kirill@shutemov.name \
    --cc=devel@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git