toruby 200th に参加しました

開催 200回 すごい!

toruby.connpass.com

家庭の都合で 1年以上参加できていませんでした。

当日、セコンさんにお声がけいただいたのと、年末なのと、200回目なのとで久々に参加です。

.... ところが、欠席の方も多かったので読書会はスキップして、西那須野駅前のダイニングバーでお話をするという会に急遽変更になりました。

  • toruby 200回目の話
  • toruby 初回の話
  • キャンプの話
  • 技術書籍の出版と編集者さんの話
  • エジプト旅行とイスラエルの話
  • キーボードをたくさん持ってる話
  • マウスも気になるって話
  • リモートワークとプロダクト開発の話
  • クルーズ船で旅行をする話
  • 熊が出る話
  • 冬の那須は風が強くて家も寒い話
  • 深夜、那須塩原駅前の駐車場で小銭がないと支払いに困る話
  • ... etc

箇条書きだとなんのこっちゃ??? という感じですが、いろんなお話をしました。

また来年〜 ✋

Notion の 前のページ、次のページのショートカットキーを Karabiner-Elements で変更する

Notion に 前のページ次のページ に遷移するショートカットキーがある

別のショートカットキーに変えたくなったので Karabiner-Elements で設定を変更する

karabiner-elements.pqrs.org

~/.config/karabiner/karabiner.json に以下の JSON を追加して option + n , option + p で遷移できるようにした 1

                    {
                        "description": "notion cmd+shift+k",
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^notion\\.id$"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "p",
                                    "modifiers": {
                                        "mandatory": [
                                            "option"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "k",
                                        "modifiers": [
                                            "control",
                                            "shift"
                                        ]
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    },
                    {
                        "description": "notion cmd+shift+j",
                        "manipulators": [
                            {
                                "conditions": [
                                    {
                                        "bundle_identifiers": [
                                            "^notion\\.id$"
                                        ],
                                        "type": "frontmost_application_if"
                                    }
                                ],
                                "from": {
                                    "key_code": "n",
                                    "modifiers": {
                                        "mandatory": [
                                            "option"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "j",
                                        "modifiers": [
                                            "control",
                                            "shift"
                                        ]
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    },

  1. 新しくどのショートカットキーを割り当てるかは個人のお好みで。Emacs でもよく使ってるキーに揃えた

TechFeed Experts Night#19 - トラブルシューティングから Linux カーネルに潜り込む の発表をしました - 書き起こし記事が公開されています

hiboma.hatenadiary.jp

こちらの続きのエントリです。


TechFeed Experts Night#19 で発表した動画とスライドは既に公開済みだったのですが、このたび新たに発表内容を書き起こした記事が追加されています。

techfeed.io

スライドに書いてない説明を口頭で補っている箇所が文章化されていますね。Linux カーネルトラブルシューティングに興味のある方、改めてご覧になって頂けると嬉しいです

謝辞

スライドに合わせて正確に用語を書き起こして markdown 化やリンク付けまでされており、非常に丁寧なお仕事をされているなと思いました。運営の皆様、あらためて ありがとうございます!

日光霧降高原 大笹牧場〜六方沢橋 🚴

しばらくまとめるのをサボっていた自転車の記録。日光霧降高原の大笹牧場〜六方沢橋まで走った

梅雨入りしたのが嘘のような晴天に恵まれました。

距離 121km 獲得標高 1514m

続きを読む

Linux: 0, 1, 2 のファイルディスクリプタを閉じて setuid したバイナリ実行の挙動を調べる - その2 ソースを調べる

下記のエントリの続きです

hiboma.hatenadiary.jp

setuid したバイナリが /dev/full, /dev/null を open する glibc 実装が分からなかったのが、先のエントリの宿題でした

あれこれ調べてみて csu/check_fds.c だと分かりました

libdw をリンクした strace だと正しいシンボルがとれた。

先のエントリでは Ubuntu Jammy で入る strace を用いて調べていました。Ubuntu Jammy の strace は libunwind をリンクしていますが、関数を正しく解決できてなかったようです。

openat(AT_FDCWD, "/dev/full", O_WRONLY|O_NOFOLLOW) = 0
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x9748) [0x26b38]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x903e) [0x2642e]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x24a5) [0x1f895]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x41c8) [0x215b8]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x2ec8) [0x202b8]

試しに libdw をリンクした strace をビルドして調べたら解決できました

openat(AT_FDCWD, "/dev/full", O_WRONLY|O_NOFOLLOW) = 0
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(__GI___open_nocancel+0x38) [0x26b38]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(__libc_check_standard_fds+0x7d) [0x2642d]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_sysdep_start+0x434) [0x1f894]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_start+0x567) [0x215b7]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_start+0x7) [0x202b7]

ちょうど「libunwind と libdw は何が違うのか?」というやりとりを TenForward id:defiant さんとしていて、先のエントリの strace 調査をやり直した経緯があります

csu/check_fds.c __libc_check_standard_fds

strace の結果、 csu/check_fds.c の __libc_check_standard_fds を追って行けばいいことが分かりました 1

それほど長くないコードなのでファイル全部張ります。 コメントもしっかりついていて わかりやすいですね

  /* If this is a SUID program we make sure that FDs 0, 1, and 2 are
     allocated.  If necessary we are doing it ourself.  If it is not
     possible we stop the program.  */
  if (__builtin_expect (__libc_enable_secure, 0))
    __libc_check_standard_fds ();

/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <https://www.gnu.org/licenses/>.  */

#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>

/* Try to get a machine dependent instruction which will make the
   program crash.  This is used in case everything else fails.  */
#include <abort-instr.h>
#ifndef ABORT_INSTRUCTION
/* No such instruction is available.  */
# define ABORT_INSTRUCTION
#endif

#include <device-nrs.h>
#include <not-cancel.h>


/* Should other OSes (e.g., Hurd) have different versions which can
   be written in a better way?  */
static void
check_one_fd (int fd, int mode)
{
  if (__builtin_expect (__fcntl64_nocancel (fd, F_GETFD), 0) == -1
      && errno == EBADF)
    {
      const char *name;
      dev_t dev;

      /* For writable descriptors we use /dev/full.  */
      if ((mode & O_ACCMODE) == O_WRONLY)
    {
      name = _PATH_DEV "full";
      dev = __gnu_dev_makedev (DEV_FULL_MAJOR, DEV_FULL_MINOR);
    }
      else
    {
      name = _PATH_DEVNULL;
      dev = __gnu_dev_makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR);
    }

      /* Something is wrong with this descriptor, it's probably not
    opened.  Open /dev/null so that the SUID program we are
    about to start does not accidentally use this descriptor.  */
      int nullfd = __open_nocancel (name, mode, 0);

      /* We are very paranoid here.  With all means we try to ensure
    that we are actually opening the /dev/null device and nothing
    else.

    Note that the following code assumes that STDIN_FILENO,
    STDOUT_FILENO, STDERR_FILENO are the three lowest file
    decsriptor numbers, in this order.  */
      struct __stat64_t64 st;
      if (__glibc_unlikely (nullfd != fd)
      || __glibc_likely (__fstat64_time64 (fd, &st) != 0)
      || __glibc_unlikely (S_ISCHR (st.st_mode) == 0)
      || st.st_rdev != dev)
    /* We cannot even give an error message here since it would
      run into the same problems.  */
    while (1)
      /* Try for ever and ever.  */
      ABORT_INSTRUCTION;
    }
}


void
__libc_check_standard_fds (void)
{
  /* Check all three standard file descriptors.  The O_NOFOLLOW flag
     is really paranoid but some people actually are.  If /dev/null
     should happen to be a symlink to somewhere else and not the
     device commonly known as "/dev/null" we bail out.  */
  check_one_fd (STDIN_FILENO, O_WRONLY | O_NOFOLLOW);
  check_one_fd (STDOUT_FILENO, O_RDONLY | O_NOFOLLOW);
  check_one_fd (STDERR_FILENO, O_RDONLY | O_NOFOLLOW);
}

試しに gdb で __libc_check_standard_fds に break point 張って実行すると ... 止まった!

(gdb) bt
#0  __libc_check_standard_fds () at ./csu/check_fds.c:88
#1  0x00007f0f4436c895 in _dl_sysdep_start (start_argptr=start_argptr@entry=0x7fff0a9b1830, dl_main=dl_main@entry=0x7f0f4436e900 <dl_main>) at ../elf/dl-sysdep.c:254
#2  0x00007f0f4436e5b8 in _dl_start_final (arg=0x7fff0a9b1830) at ./elf/rtld.c:507
#3  _dl_start (arg=0x7fff0a9b1830) at ./elf/rtld.c:596
#4  0x00007f0f4436d2b8 in _start () from /lib64/ld-linux-x86-64.so.2
#5  0x0000000000000001 in ?? ()
#6  0x00007fff0a9b276b in ?? ()
#7  0x0000000000000000 in ?? ()

ディレクトリ名の csu とは?

ディレクトリ名の csu って何だろうと? 調べたら stack overflow で回答を見つけました

stackoverflow.com

I found a reference to "C start up" in the libc mailing list. It's far from definitive, but I imagine it's probably correct given what the function does.

ここの ML の回答を指しているみたいですね。多分あってそうな??

sourceware.org

ABORT_INSTRUCTION は?

ABORT_INSTRUCTION を呼ぶコードが混じっています。これは以前 会社のテックブログにまとめたのを思い出しました

tech.pepabo.com

感謝

このエントリを書いてる途中、id:NeoCat さんからコメントいただいておりました! ありがとうございます

コメントは先のエントリにいただいております。

hiboma.hatenadiary.jp


  1. NeoCat さんからのコメントで確かであることを再確認

Linux: 0, 1, 2 のファイルディスクリプタを閉じて setuid したバイナリ実行の挙動を調べる

以下の記事を読んで setuid したバイナリを実行する挙動で新たに知ったことがあった

lwn.net

以下に引用する

Some OSes (e.g., OpenBSD) protect against this by opening /dev/null on any unused FDs in the 0-2 range when execing a setuid program. As far as I can tell, Linux does not (but maybe I'm missing something...). This behavior is permitted in POSIX.1-2001, but not before.


いくつかの OS (たとえば OpenBSD) は、setuid プログラムを実行するときに、0-2 の範囲の未使用の FD で /dev/null をオープンして、この問題を防いでいます。私の知る限り、Linuxはそうではありません(しかし、もしかしたら私は何かを見逃しているかもしれません...)。この動作はPOSIX.1-2001では許可されているが、それ以前は許可されていない。

DeepL 翻訳

OpenBSD の execve(2) の man にも 下記の説明が付いている

     In the case of a new setuid or setgid executable being exe-
     cuted, if file descriptors 0, 1, or 2 (representing stdin, stdout, and
     stderr) are currently unallocated, these descriptors will be opened to
     point to some system file like /dev/null. The intent is to ensure these
     descriptors are not unallocated, since many libraries make assumptions
     about the use of these 3 file descriptors.

なるほどなー 。実際にどうなんだろうと Linux で試した。

実験環境

Ubuntu Jammy で実験をします

hiboma@vps:~$ uname -a
Linux vps 5.15.0-60-generic #66-Ubuntu SMP Fri Jan 20 14:29:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

hiboma@vps:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:    22.04
Codename:   jammy

実験用のコード

C のコードで sleep するだけの setuid バイナリを用意します。

#include <unistd.h>

int main() {
    sleep(100);
}

以下の手順で setuid なバイナリとします。

$ gcc setuid-sleep.c -o setuid-sleep
$ sudo chown root.root setuid-sleep 
$ sudo chmod 4755 setuid-sleep 

$ ls -hal setuid-sleep
-rwsr-xr-x 1 root root 16K Jun  7 10:24 setuid-sleep

0, 1, 2 のファイルディスクリプタを閉じてから 1 setuid なバイナリを実行する bashシェルスクリプトも用意します

#!/bin/bash                                                                                                                                                                                                      
                                                                                                                                                                                                                 
exec 0<&-                                                                                                                                                                                                        
exec 1<&-                                                                                                                                                                                                        
exec 2<&-                                                                                                                                                                                                        
                                                                                                                                                                                                                 
exec ./setuid-sleep                                                                                                                                                                                              

実験

シェルスクリプトを実行します。これで 0, 1, 2 のデスクリプタを閉じて setuid したバイナリを exec できます。

$ ./test.sh

setuid したバイナリを実行しているプロセスの lsof をとって見ます。

$ sudo lsof -p $(pgrep setuid-sleep)
COMMAND       PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
setuid-sl 1120951 root  cwd    DIR  252,2     4096 134434 /home/hiboma
setuid-sl 1120951 root  rtd    DIR  252,2     4096      2 /
setuid-sl 1120951 root  txt    REG  252,2    15968 135566 /home/hiboma/setuid-sleep
setuid-sl 1120951 root  mem    REG  252,2  2216304   4337 /usr/lib/x86_64-linux-gnu/libc.so.6
setuid-sl 1120951 root  mem    REG  252,2   240936    194 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
setuid-sl 1120951 root    0w   CHR    1,7      0t0      8 /dev/full 👈
setuid-sl 1120951 root    1r   CHR    1,3      0t0      5 /dev/null 👈
setuid-sl 1120951 root    2r   CHR    1,3      0t0      5 /dev/null 👈

/dev/full, /dev/null を開いていますね!

/dev/full, /dev/null を open するのはどこ?

strace をとって調べて見たところ、ld-linux-x86-64.so.2 っぽい。

openat(AT_FDCWD, "/dev/full", O_WRONLY|O_NOFOLLOW) = 0
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x9748) [0x26b38]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x903e) [0x2642e]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x24a5) [0x1f895]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x41c8) [0x215b8]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x2ec8) [0x202b8]

... 略


openat(AT_FDCWD, "/dev/null", O_RDONLY|O_NOFOLLOW) = 1
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x9748) [0x26b38]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x907e) [0x2646e]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x24a5) [0x1f895]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x41c8) [0x215b8]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x2ec8) [0x202b8]

... 略


openat(AT_FDCWD, "/dev/null", O_RDONLY|O_NOFOLLOW) = 2
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x9748) [0x26b38]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x90c2) [0x264b2]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x24a5) [0x1f895]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x41c8) [0x215b8]
 > /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2(_dl_catch_error+0x2ec8) [0x202b8]

ソースは?

  • どういう実装になっているのかも気になって glibc のソースを辿ってみたのでしたが、分からず
  • _dl_catch_error 周りも複雑でわからん。 slack-gpt の回答は以下の通りだった

_dl_catch_errorは、GNU Cライブラリ (glibc) の内部で使用される関数です。この関数は、動的リンカーによる共有ライブラリのロードやシンボルの解決中に発生するエラーをキャッチ(捉え)する役割を果たします。


具体的には、_dl_catch_errorは以下のような機能を提供します: 1. エラーハンドラの設定: エラーが発生した際に呼び出される関数を設定できます。これにより、バリエーションに富むエラーハンドリングを行うことができます。

  1. エラーの発生処理: _dl_catch_error は、エラーが発生した際にエラーメッセージを生成し、設定されたエラーハンドラに渡します。これにより、詳細なエラー情報が収集され、適切なエラー処理が行われます。

  2. エラーハンドラのリセット: エラーが捉えられた後には、元の状態に戻します。_dl_catch_errorはビルトインのエラー処理機能を提供することで、動的リンカーによる共有ライブラリのロードやシンボルの解決を安全かつ信頼性の高いものにする役割を果たします

実験の補足

ファイルディスクリプタを閉じずに setuid バイナリを実行すると、0, 1, 2 のファイルディスクリプタ/dev/pts を指していました

~$ sudo lsof -p $(pgrep setuid-sleep)
COMMAND       PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
setuid-sl 1125289 root  cwd    DIR  252,2     4096 134434 /home/hiboma
setuid-sl 1125289 root  rtd    DIR  252,2     4096      2 /
setuid-sl 1125289 root  txt    REG  252,2    15968 135566 /home/hiboma/setuid-sleep
setuid-sl 1125289 root  mem    REG  252,2  2216304   4337 /usr/lib/x86_64-linux-gnu/libc.so.6
setuid-sl 1125289 root  mem    REG  252,2   240936    194 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
setuid-sl 1125289 root    0u   CHR  136,1      0t0      4 /dev/pts/1
setuid-sl 1125289 root    1u   CHR  136,1      0t0      4 /dev/pts/1
setuid-sl 1125289 root    2u   CHR  136,1      0t0      4 /dev/pts/1

感想

  • 細かいプロセスの挙動ではまだまだ知らないことがある
  • /dev/full, /dev/null を open する実装がどこにあるのか気になる

関連エントリ

hiboma.hatenadiary.jp

hiboma.hatenadiary.jp


  1. シェルスクリプトでファイルディスクリプタを閉じる、って全然書いたことがなくて やり方を知らなかった

strace の -k オプションでスタックトレースを出す - 2023 Ubuntu Jammy 版

以前こんなエントリを書いていた

hiboma.hatenadiary.jp

strace で -k を指定すると システムコール呼び出しのスタックトレースを採取できるのを知った。v4.9 から使える experimental 扱いのオプション

という内容のエントリでした。


 

しかしながら

CentOS7.4 の strace-4.12-4.el7 ではサポートされていない機能だ。ざんねーん ちなみに Ubuntu Xenial もだめだー。とほほー

当時、私が業務で扱っていた Linux ディストリビューションではサポートされていなかったのでした。


で、この内容を改めて思い出して、 Ubuntu Jammy で strace -k を試してみたら 動く!

hiboma@vps:~$ strace -k -P /etc/passwd -y id
openat(AT_FDCWD</home/hiboma>, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3</etc/passwd>
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__open64_nocancel+0x4c) [0x119bcc]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_file_open+0xd5) [0x8c1e5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_file_fopen+0x292) [0x8c492]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(fopen+0x7e) [0x7f72e]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__nss_files_fopen+0x12) [0x154e32]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_nss_files_getpwuid_r+0x3e) [0x15ab4e]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid_r+0x11f) [0xe9e0f]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid+0xa3) [0xe9683]
 > /usr/bin/id() [0x621e]
 > /usr/bin/id() [0x2fc5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x90) [0x29d90]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x29e40]
 > /usr/bin/id() [0x32e5]
newfstatat(3</etc/passwd>, "", {st_mode=S_IFREG|0644, st_size=1889, ...}, AT_EMPTY_PATH) = 0
 > /usr/lib/x86_64-linux-gnu/libc.so.6(fstatat+0xe) [0x113eee]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_file_doallocate+0x63) [0x7ebf3]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_doallocbuf+0x50) [0x8dd60]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_file_seekoff+0x135) [0x8aa95]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(fseeko+0x63) [0x88d53]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__nss_files_fopen+0x2c) [0x154e4c]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_nss_files_getpwuid_r+0x3e) [0x15ab4e]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid_r+0x11f) [0xe9e0f]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid+0xa3) [0xe9683]
 > /usr/bin/id() [0x621e]
 > /usr/bin/id() [0x2fc5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x90) [0x29d90]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x29e40]
 > /usr/bin/id() [0x32e5]
lseek(3</etc/passwd>, 0, SEEK_SET)      = 0
 > /usr/lib/x86_64-linux-gnu/libc.so.6(llseek+0xb) [0x114acb]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_file_seekoff+0x22d) [0x8ab8d]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(fseeko+0x63) [0x88d53]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__nss_files_fopen+0x2c) [0x154e4c]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_nss_files_getpwuid_r+0x3e) [0x15ab4e]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid_r+0x11f) [0xe9e0f]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid+0xa3) [0xe9683]
 > /usr/bin/id() [0x621e]
 > /usr/bin/id() [0x2fc5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x90) [0x29d90]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x29e40]
 > /usr/bin/id() [0x32e5]
read(3</etc/passwd>, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 1889
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__read_nocancel+0x8) [0x119cd8]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_file_underflow+0x186) [0x8ccb6]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_default_uflow+0x36) [0x8de16]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_getline_info+0xac) [0x8049c]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(fgets_unlocked+0x45) [0x8a3b5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__nss_readline+0x4b) [0x154ecb]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_nss_files_getpwuid_r+0x82) [0x15ab92]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid_r+0x11f) [0xe9e0f]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid+0xa3) [0xe9683]
 > /usr/bin/id() [0x621e]
 > /usr/bin/id() [0x2fc5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x90) [0x29d90]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x29e40]
 > /usr/bin/id() [0x32e5]
close(3</etc/passwd>)                   = 0
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__close_nocancel+0xb) [0x119a1b]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_file_close_it+0x70) [0x8bf80]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_IO_fclose+0x11f) [0x7ee0f]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(_nss_files_getpwuid_r+0xd5) [0x15abe5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid_r+0x11f) [0xe9e0f]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(getpwuid+0xa3) [0xe9683]
 > /usr/bin/id() [0x621e]
 > /usr/bin/id() [0x2fc5]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x90) [0x29d90]
 > /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x29e40]
 > /usr/bin/id() [0x32e5]
uid=1000(hiboma) gid=1000(hiboma) groups=1000(hiboma),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev)
+++ exited with 0 +++

やったー! すぐにつかえる!

動作環境

hiboma@vps:~$ uname -a
Linux vps 5.15.0-60-generic #66-Ubuntu SMP Fri Jan 20 14:29:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
hiboma@vps:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:    22.04
Codename:   jammy
hiboma@vps:~$ 

感想

  • 見慣れないオプションがたくさんあるから もうちょい調べてみたい
  • 最近は strace 使ってあれこれ調べるって機会、減ったなぁ