← Documents Documentation/security/sak.rst GitHub 원문 ↗

Linux 6.18.37 · Security

Linux Secure Attention Key 처리

Linux SAK의 목적과 loadkeys 설정, /dev/console 보유 프로세스 종료 범위 및 daemon 파일 설명자 문제를 설명합니다.

Source pathDocumentation/security/sak.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

sak.rst:1-91

Linux SAK의 목적과 loadkeys 설정, /dev/console 보유 프로세스 종료 범위 및 daemon 파일 설명자 문제를 설명합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 =========================================
2 Linux Secure Attention Key (SAK) handling
3 =========================================
4
5 :Date: 18 March 2001
6 :Author: Andrew Morton
7
8 An operating system's Secure Attention Key is a security tool which is
9 provided as protection against trojan password capturing programs. It
10 is an undefeatable way of killing all programs which could be
11 masquerading as login applications. Users need to be taught to enter
12 this key sequence before they log in to the system.
13
14 From the PC keyboard, Linux has two similar but different ways of
15 providing SAK. One is the ALT-SYSRQ-K sequence. You shouldn't use
16 this sequence. It is only available if the kernel was compiled with
17 sysrq support.
18
19 The proper way of generating a SAK is to define the key sequence using
20 ``loadkeys``. This will work whether or not sysrq support is compiled
21 into the kernel.
22
23 SAK works correctly when the keyboard is in raw mode. This means that
24 once defined, SAK will kill a running X server. If the system is in
25 run level 5, the X server will restart. This is what you want to
26 happen.
27
28 What key sequence should you use? Well, CTRL-ALT-DEL is used to reboot
29 the machine. CTRL-ALT-BACKSPACE is magical to the X server. We'll
30 choose CTRL-ALT-PAUSE.
31
32 In your rc.sysinit (or rc.local) file, add the command::
33
34 echo "control alt keycode 101 = SAK" | /bin/loadkeys
35
36 And that's it! Only the superuser may reprogram the SAK key.
37
38
39 .. note::
40
41 1. Linux SAK is said to be not a "true SAK" as is required by
42 systems which implement C2 level security. This author does not
43 know why.
44
45
46 2. On the PC keyboard, SAK kills all applications which have
47 /dev/console opened.
48
49 Unfortunately this includes a number of things which you don't
50 actually want killed. This is because these applications are
51 incorrectly holding /dev/console open. Be sure to complain to your
52 Linux distributor about this!
53
54 You can identify processes which will be killed by SAK with the
55 command::
56
57 # ls -l /proc/[0-9]*/fd/* | grep console
58 l-wx------ 1 root root 64 Mar 18 00:46 /proc/579/fd/0 -> /dev/console
59
60 Then::
61
62 # ps aux|grep 579
63 root 579 0.0 0.1 1088 436 ? S 00:43 0:00 gpm -t ps/2
64
65 So ``gpm`` will be killed by SAK. This is a bug in gpm. It should
66 be closing standard input. You can work around this by finding the
67 initscript which launches gpm and changing it thusly:
68
69 Old::
70
71 daemon gpm
72
73 New::
74
75 daemon gpm < /dev/null
76
77 Vixie cron also seems to have this problem, and needs the same treatment.
78
79 Also, one prominent Linux distribution has the following three
80 lines in its rc.sysinit and rc scripts::
81
82 exec 3<&0
83 exec 4>&1
84 exec 5>&2
85
86 These commands cause **all** daemons which are launched by the
87 initscripts to have file descriptors 3, 4 and 5 attached to
88 /dev/console. So SAK kills them all. A workaround is to simply
89 delete these lines, but this may cause system management
90 applications to malfunction - test everything well.
91
92

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

SAK 목적과 설정

1-37

운영체제의 Secure Attention Key(SAK)는 Trojan password capture 프로그램을 방어하는 보안 수단이다. login 응용 프로그램으로 위장할 수 있는 모든 프로그램을 확실히 종료하며, 사용자는 시스템에 로그인하기 전에 이 키 조합을 누르도록 교육받아야 한다.

PC keyboard에서 Linux는 비슷하지만 다른 두 방법을 제공한다. `ALT-SYSRQ-K`는 sysrq 지원을 넣어 커널을 빌드했을 때만 사용할 수 있으므로 사용하지 말아야 한다. 올바른 방법은 `loadkeys`로 SAK key sequence를 정의하는 것이며, 이 방식은 커널의 sysrq 지원 여부와 관계없이 동작한다.

SAK는 keyboard raw mode에서도 올바르게 동작하므로 정의된 SAK는 실행 중인 X server를 종료한다. run level 5에서는 X server가 다시 시작하며 이것이 의도한 결과다. `CTRL-ALT-DEL`은 재부팅에, `CTRL-ALT-BACKSPACE`는 X server 기능에 쓰이므로 예제는 `CTRL-ALT-PAUSE`를 선택한다.

`rc.sysinit` 또는 `rc.local`에 `echo "control alt keycode 101 = SAK" | /bin/loadkeys`를 추가한다. SAK key를 다시 프로그래밍할 수 있는 주체는 superuser뿐이다.

SAK 사용 흐름
superuser가 loadkeys로 SAK 정의사용자가 로그인 전 키 조합 입력/dev/console 보유 응용 종료X server 재시작 가능깨끗한 login 화면에서 인증

로그인 전 신뢰할 수 있는 입력 경로를 확보한다.

=========================================
Linux Secure Attention Key (SAK) handling
=========================================

:Date: 18 March 2001
:Author: Andrew Morton

An operating system's Secure Attention Key is a security tool which is
provided as protection against trojan password capturing programs.  It
is an undefeatable way of killing all programs which could be
masquerading as login applications.  Users need to be taught to enter
this key sequence before they log in to the system.

From the PC keyboard, Linux has two similar but different ways of
providing SAK.  One is the ALT-SYSRQ-K sequence.  You shouldn't use
this sequence.  It is only available if the kernel was compiled with
sysrq support.

The proper way of generating a SAK is to define the key sequence using
``loadkeys``.  This will work whether or not sysrq support is compiled
into the kernel.

SAK works correctly when the keyboard is in raw mode.  This means that
once defined, SAK will kill a running X server.  If the system is in
run level 5, the X server will restart.  This is what you want to
happen.

What key sequence should you use? Well, CTRL-ALT-DEL is used to reboot
the machine.  CTRL-ALT-BACKSPACE is magical to the X server.  We'll
choose CTRL-ALT-PAUSE.

In your rc.sysinit (or rc.local) file, add the command::

        echo "control alt keycode 101 = SAK" | /bin/loadkeys

And that's it!  Only the superuser may reprogram the SAK key.

한계와 종료 대상 확인

38-65

문서는 Linux SAK가 C2 수준 보안 시스템이 요구하는 ‘true SAK’가 아니라고 알려져 있지만 저자는 그 이유를 모른다고 적는다. PC keyboard의 SAK는 `/dev/console`을 열어 둔 모든 응용 프로그램을 종료한다.

문제는 종료할 필요가 없는 프로그램도 `/dev/console`을 잘못 열어 둔 경우 함께 종료된다는 점이다. `ls -l /proc/[0-9]*/fd/* | grep console`로 console을 가리키는 파일 설명자를 찾고, 이어 `ps aux|grep PID`로 해당 프로세스를 식별할 수 있다. 예제에서는 `gpm -t ps/2` 프로세스가 표준 입력으로 `/dev/console`을 열어 두어 SAK로 종료된다.

SAK 종료 대상 조사
단계명령확인 내용
FD 검색ls -l /proc/[0-9]*/fd/* | grep console/dev/console을 가리키는 FD
프로세스 확인ps aux | grep PID종료될 프로그램 이름과 실행 인자

프로세스의 console 파일 설명자를 PID와 연결한다.


.. note::

  1. Linux SAK is said to be not a "true SAK" as is required by
     systems which implement C2 level security.  This author does not
     know why.


  2. On the PC keyboard, SAK kills all applications which have
     /dev/console opened.

     Unfortunately this includes a number of things which you don't
     actually want killed.  This is because these applications are
     incorrectly holding /dev/console open.  Be sure to complain to your
     Linux distributor about this!

     You can identify processes which will be killed by SAK with the
     command::

        # ls -l /proc/[0-9]*/fd/* | grep console
        l-wx------    1 root     root           64 Mar 18 00:46 /proc/579/fd/0 -> /dev/console

     Then::

        # ps aux|grep 579
        root       579  0.0  0.1  1088  436 ?        S    00:43   0:00 gpm -t ps/2

     So ``gpm`` will be killed by SAK.  This is a bug in gpm.  It should

gpm과 cron의 console 상속 수정

66-78

`gpm`은 표준 입력을 닫아야 한다. gpm을 시작하는 init script의 기존 `daemon gpm`을 `daemon gpm < /dev/null`로 바꾸면 `/dev/console` 대신 `/dev/null`을 표준 입력으로 사용해 의도치 않은 SAK 종료를 피할 수 있다. Vixie cron도 같은 문제가 있어 동일한 처리가 필요하다.

Daemon 수정
SAK로 종료되는 daemon 식별시작 스크립트 확인표준 입력을 /dev/null로 redirectdaemon 재시작console FD가 사라졌는지 재검사

불필요하게 상속된 console 입력을 끊는다.

     be closing standard input.  You can work around this by finding the
     initscript which launches gpm and changing it thusly:

     Old::

        daemon gpm

     New::

        daemon gpm < /dev/null

     Vixie cron also seems to have this problem, and needs the same treatment.

init script의 추가 파일 설명자 문제

79-91

한 주요 Linux 배포판은 `rc.sysinit`과 rc script에 `exec 3<&0`, `exec 4>&1`, `exec 5>&2`를 넣었다. 이 명령은 init script가 실행하는 모든 daemon의 파일 설명자 3, 4, 5를 `/dev/console`에 연결하므로 SAK가 그 daemon을 모두 종료하게 한다.

단순한 우회책은 세 줄을 삭제하는 것이지만 시스템 관리 응용 프로그램이 오작동할 수 있다. 따라서 변경 뒤 관련 관리 기능과 daemon 동작을 모두 충분히 시험해야 한다.

상속되는 파일 설명자
명령복제 방향영향
exec 3<&0stdin → fd 3console 입력 상속
exec 4>&1stdout → fd 4console 출력 상속
exec 5>&2stderr → fd 5console 오류 출력 상속

rc script의 복제가 모든 하위 daemon에 console 연결을 전파한다.

     Also, one prominent Linux distribution has the following three
     lines in its rc.sysinit and rc scripts::

        exec 3<&0
        exec 4>&1
        exec 5>&2

     These commands cause **all** daemons which are launched by the
     initscripts to have file descriptors 3, 4 and 5 attached to
     /dev/console.  So SAK kills them all.  A workaround is to simply
     delete these lines, but this may cause system management
     applications to malfunction - test everything well.