← Documents Documentation/usb/authorization.rst GitHub 원문 ↗

Linux 6.18.37 · USB

USB 장치의 시스템 연결 승인과 차단

USB 장치와 interface의 sysfs 승인 제어, 기본 잠금 정책, udev 연계, 안전한 인증과 driver probe 순서를 설명합니다.

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

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

1. 요약·해설

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

요약·해설

authorization.rst:1-129

USB authorization은 장치 전체 또는 개별 interface를 sysfs에서 승인·차단하는 정책 장치입니다. 기본 차단 후 udev에서 선별 승인할 수 있지만 descriptor 값만으로 신뢰를 판단하면 쉽게 위조됩니다. 실제 보안 정책은 certificate 기반 인증을 사용하고, 다중 interface driver는 모든 필수 interface를 승인한 뒤 probe해야 합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 ==============================================================
2 Authorizing (or not) your USB devices to connect to the system
3 ==============================================================
4
5 Copyright (C) 2007 Inaky Perez-Gonzalez <[email protected]> Intel Corporation
6
7 This feature allows you to control if a USB device can be used (or
8 not) in a system. This feature will allow you to implement a lock-down
9 of USB devices, fully controlled by user space.
10
11 As of now, when a USB device is connected it is configured and
12 its interfaces are immediately made available to the users. With this
13 modification, only if root authorizes the device to be configured will
14 then it be possible to use it.
15
16 Usage
17 =====
18
19 Authorize a device to connect::
20
21 $ echo 1 > /sys/bus/usb/devices/DEVICE/authorized
22
23 De-authorize a device::
24
25 $ echo 0 > /sys/bus/usb/devices/DEVICE/authorized
26
27 Set new devices connected to hostX to be deauthorized by default (ie:
28 lock down)::
29
30 $ echo 0 > /sys/bus/usb/devices/usbX/authorized_default
31
32 Remove the lock down::
33
34 $ echo 1 > /sys/bus/usb/devices/usbX/authorized_default
35
36 By default, all USB devices are authorized. Writing "2" to the
37 authorized_default attribute causes the kernel to authorize by default
38 only devices connected to internal USB ports.
39
40
41 Example system lockdown (lame)
42 ------------------------------
43
44 Imagine you want to implement a lockdown so only devices of type XYZ
45 can be connected (for example, it is a kiosk machine with a visible
46 USB port)::
47
48 boot up
49 rc.local ->
50
51 for host in /sys/bus/usb/devices/usb*
52 do
53 echo 0 > $host/authorized_default
54 done
55
56 Hookup an script to udev, for new USB devices::
57
58 if device_is_my_type $DEV
59 then
60 echo 1 > $device_path/authorized
61 done
62
63
64 Now, device_is_my_type() is where the juice for a lockdown is. Just
65 checking if the class, type and protocol match something is the worse
66 security verification you can make (or the best, for someone willing
67 to break it). If you need something secure, use crypto and Certificate
68 Authentication or stuff like that. Something simple for an storage key
69 could be::
70
71 function device_is_my_type()
72 {
73 echo 1 > authorized # temporarily authorize it
74 # FIXME: make sure none can mount it
75 mount DEVICENODE /mntpoint
76 sum=$(md5sum /mntpoint/.signature)
77 if [ $sum = $(cat /etc/lockdown/keysum) ]
78 then
79 echo "We are good, connected"
80 umount /mntpoint
81 # Other stuff so others can use it
82 else
83 echo 0 > authorized
84 fi
85 }
86
87
88 Of course, this is lame, you'd want to do a real certificate
89 verification stuff with PKI, so you don't depend on a shared secret,
90 etc, but you get the idea. Anybody with access to a device gadget kit
91 can fake descriptors and device info. Don't trust that. You are
92 welcome.
93
94
95 Interface authorization
96 -----------------------
97
98 There is a similar approach to allow or deny specific USB interfaces.
99 That allows to block only a subset of an USB device.
100
101 Authorize an interface::
102
103 $ echo 1 > /sys/bus/usb/devices/INTERFACE/authorized
104
105 Deauthorize an interface::
106
107 $ echo 0 > /sys/bus/usb/devices/INTERFACE/authorized
108
109 The default value for new interfaces
110 on a particular USB bus can be changed, too.
111
112 Allow interfaces per default::
113
114 $ echo 1 > /sys/bus/usb/devices/usbX/interface_authorized_default
115
116 Deny interfaces per default::
117
118 $ echo 0 > /sys/bus/usb/devices/usbX/interface_authorized_default
119
120 Per default the interface_authorized_default bit is 1.
121 So all interfaces would authorized per default.
122
123 Note:
124 If a deauthorized interface will be authorized so the driver probing must
125 be triggered manually by writing INTERFACE to /sys/bus/usb/drivers_probe
126
127 For drivers that need multiple interfaces all needed interfaces should be
128 authorized first. After that the drivers should be probed.
129 This avoids side effects.
130

3. 한국어 전문 번역

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

제목, 저작권

1-5

이 문서는 USB 장치가 시스템에 연결되어 사용되는 것을 승인하거나 차단하는 방법을 설명합니다.

Copyright (C) 2007 Inaky Perez-Gonzalez `<[email protected]>`, Intel Corporation입니다.

==============================================================
Authorizing (or not) your USB devices to connect to the system
==============================================================

Copyright (C) 2007 Inaky Perez-Gonzalez <[email protected]> Intel Corporation

사용자 공간이 제어하는 USB 잠금

6-14

이 기능을 사용하면 시스템에서 특정 USB 장치를 사용할 수 있는지 제어할 수 있습니다. 따라서 USB 장치 잠금 정책을 사용자 공간에서 완전히 관리할 수 있습니다.

일반적으로 USB 장치를 연결하면 즉시 구성되고 인터페이스가 사용자에게 공개됩니다. 이 변경을 적용한 환경에서는 `root`가 장치 구성을 승인한 경우에만 그 장치를 사용할 수 있습니다.


This feature allows you to control if a USB device can be used (or
not) in a system. This feature will allow you to implement a lock-down
of USB devices, fully controlled by user space.

As of now, when a USB device is connected it is configured and
its interfaces are immediately made available to the users.  With this
modification, only if root authorizes the device to be configured will
then it be possible to use it.

장치 승인과 기본 정책

15-38

장치의 `authorized` 속성에 `1`을 쓰면 연결 사용을 승인하고, `0`을 쓰면 승인을 취소합니다. `DEVICE`는 sysfs의 실제 USB 장치 이름으로 바꿉니다.

특정 host `usbX`에 새로 연결되는 장치를 기본적으로 차단하려면 `authorized_default`에 `0`을 씁니다. 잠금을 해제하려면 같은 속성에 `1`을 씁니다.

기본 상태에서는 모든 USB 장치가 승인됩니다. `authorized_default`에 `2`를 쓰면 커널은 내부 USB port에 연결된 장치만 기본 승인합니다.

USB 장치 승인용 sysfs 값
대상경로효과
개별 장치/sys/bus/usb/devices/DEVICE/authorized1장치 사용 승인
개별 장치/sys/bus/usb/devices/DEVICE/authorized0장치 승인 취소
host 기본값/sys/bus/usb/devices/usbX/authorized_default0새 장치 기본 차단
host 기본값/sys/bus/usb/devices/usbX/authorized_default1새 장치 기본 승인
host 기본값/sys/bus/usb/devices/usbX/authorized_default2내부 port 장치만 기본 승인

장치별 승인과 host별 기본 정책의 경로 및 값을 정리합니다.


Usage
=====

Authorize a device to connect::

	$ echo 1 > /sys/bus/usb/devices/DEVICE/authorized

De-authorize a device::

	$ echo 0 > /sys/bus/usb/devices/DEVICE/authorized

Set new devices connected to hostX to be deauthorized by default (ie:
lock down)::

	$ echo 0 > /sys/bus/usb/devices/usbX/authorized_default

Remove the lock down::

	$ echo 1 > /sys/bus/usb/devices/usbX/authorized_default

By default, all USB devices are authorized.  Writing "2" to the
authorized_default attribute causes the kernel to authorize by default
only devices connected to internal USB ports.

예제 잠금 시나리오

39-46

예를 들어 외부에 USB port가 노출된 kiosk에서 XYZ 유형 장치만 허용하려고 한다고 가정합니다. 다음 예제는 부팅 시 모든 USB host의 새 장치 기본 승인을 끄고, 이후 정책에 맞는 장치만 선택적으로 승인하는 구상입니다.



Example system lockdown (lame)
------------------------------

Imagine you want to implement a lockdown so only devices of type XYZ
can be connected (for example, it is a kiosk machine with a visible
USB port)::

부팅 잠금과 udev 승인 흐름

47-61

부팅 과정의 `rc.local`에서는 `/sys/bus/usb/devices/usb*`를 순회하며 각 host의 `authorized_default`에 `0`을 기록합니다. 이때부터 새 USB 장치는 기본적으로 차단됩니다.

새 USB 장치가 나타날 때 실행되는 udev script에서는 `device_is_my_type $DEV`로 정책을 검사합니다. 검사에 성공한 경우에만 `$device_path/authorized`에 `1`을 기록해 장치를 승인합니다.

USB 장치 잠금과 선택적 승인
부팅 시 각 usbX/authorized_default에 0 기록새 USB 장치 연결과 udev event 발생device_is_my_type가 장치 정책 검사검사 성공 시 DEVICE/authorized에 1 기록실패한 장치는 미승인 상태 유지

host 기본 차단 이후 udev 정책 검사를 통과한 장치만 승인되는 흐름입니다.


  boot up
  rc.local ->

   for host in /sys/bus/usb/devices/usb*
   do
      echo 0 > $host/authorized_default
   done

Hookup an script to udev, for new USB devices::

 if device_is_my_type $DEV
 then
   echo 1 > $device_path/authorized
 done

장치 식별의 보안 한계

62-69

실제 잠금 정책의 핵심은 `device_is_my_type()`입니다. class, type, protocol이 예상값과 일치하는지만 확인하는 것은 가장 취약한 보안 검증이며, 공격자가 우회하기도 가장 쉽습니다.

보안이 필요하다면 암호 기술과 certificate authentication을 사용해야 합니다. 다음 저장 장치 예제는 원리를 보여 주지만 안전한 완성품이 아닙니다.



Now, device_is_my_type() is where the juice for a lockdown is. Just
checking if the class, type and protocol match something is the worse
security verification you can make (or the best, for someone willing
to break it). If you need something secure, use crypto and Certificate
Authentication or stuff like that. Something simple for an storage key
could be::

저장 장치 서명 검사 예제

70-85

예제 함수는 장치를 잠시 승인하고 `DEVICENODE`를 `/mntpoint`에 mount한 다음, `.signature`의 `md5sum`을 `/etc/lockdown/keysum`과 비교합니다.

합계가 일치하면 연결을 인정하고 unmount한 뒤 다른 사용자가 쓸 수 있도록 후속 처리를 합니다. 일치하지 않으면 `authorized`에 `0`을 써서 다시 차단합니다.

주석의 FIXME가 지적하듯 임시 승인 중 다른 주체가 장치를 mount하지 못하도록 보장해야 합니다. 또한 MD5와 공유 비밀에 의존하는 이 코드는 보안 구현이 아니라 설명용 의사 코드입니다.


 function device_is_my_type()
 {
   echo 1 > authorized		# temporarily authorize it
                                # FIXME: make sure none can mount it
   mount DEVICENODE /mntpoint
   sum=$(md5sum /mntpoint/.signature)
   if [ $sum = $(cat /etc/lockdown/keysum) ]
   then
        echo "We are good, connected"
        umount /mntpoint
        # Other stuff so others can use it
   else
        echo 0 > authorized
   fi
 }

PKI와 descriptor 위조 경고

86-92

실제 시스템에서는 공유 비밀에 의존하지 않도록 PKI 기반 certificate 검증을 구현해야 합니다. 장치 gadget kit에 접근할 수 있는 사람은 descriptor와 장치 정보를 위조할 수 있으므로 이를 신뢰의 근거로 삼아서는 안 됩니다.



Of course, this is lame, you'd want to do a real certificate
verification stuff with PKI, so you don't depend on a shared secret,
etc, but you get the idea. Anybody with access to a device gadget kit
can fake descriptors and device info. Don't trust that. You are
welcome.

USB 인터페이스별 승인

93-100

USB 장치 전체와 비슷하게 특정 USB interface를 허용하거나 거부할 수도 있습니다. 이 방식은 복합 USB 장치의 일부 interface만 차단해야 할 때 유용합니다.



Interface authorization
-----------------------

There is a similar approach to allow or deny specific USB interfaces.
That allows to block only a subset of an USB device.

인터페이스 승인 명령과 기본값

101-121

개별 `INTERFACE`의 `authorized`에 `1`을 쓰면 승인하고 `0`을 쓰면 승인을 취소합니다.

특정 USB bus에서 새 interface의 기본 정책은 `usbX/interface_authorized_default`로 정합니다. `1`은 기본 허용, `0`은 기본 거부이며 초기 기본값은 `1`이므로 별도 설정이 없으면 모든 interface가 승인됩니다.

USB 인터페이스 승인용 sysfs 값
대상경로효과
개별 interface/sys/bus/usb/devices/INTERFACE/authorized1interface 승인
개별 interface/sys/bus/usb/devices/INTERFACE/authorized0interface 승인 취소
bus 기본값/sys/bus/usb/devices/usbX/interface_authorized_default1새 interface 기본 허용
bus 기본값/sys/bus/usb/devices/usbX/interface_authorized_default0새 interface 기본 거부

개별 interface와 bus 기본값을 구분합니다.

Authorize an interface::

	$ echo 1 > /sys/bus/usb/devices/INTERFACE/authorized

Deauthorize an interface::

	$ echo 0 > /sys/bus/usb/devices/INTERFACE/authorized

The default value for new interfaces
on a particular USB bus can be changed, too.

Allow interfaces per default::

	$ echo 1 > /sys/bus/usb/devices/usbX/interface_authorized_default

Deny interfaces per default::

	$ echo 0 > /sys/bus/usb/devices/usbX/interface_authorized_default

Per default the interface_authorized_default bit is 1.
So all interfaces would authorized per default.

재승인 후 driver probe

122-129

차단했던 interface를 다시 승인하더라도 driver probing은 자동으로 재개되지 않을 수 있습니다. 이 경우 `INTERFACE` 이름을 `/sys/bus/usb/drivers_probe`에 써서 probe를 수동으로 시작해야 합니다.

여러 interface를 함께 요구하는 driver라면 필요한 interface를 모두 먼저 승인한 뒤 driver를 probe해야 합니다. 이 순서는 일부 interface만 준비된 상태에서 probe할 때 생길 수 있는 부작용을 피합니다.


Note:
  If a deauthorized interface will be authorized so the driver probing must
  be triggered manually by writing INTERFACE to /sys/bus/usb/drivers_probe

For drivers that need multiple interfaces all needed interfaces should be
authorized first. After that the drivers should be probed.
This avoids side effects.