Linux-Mint

無法啟動褲子服務 - 給出錯誤“TrouSerS ioctl: (25) Inappropriate ioctl for device”

  • November 13, 2021

我已經使用 bios 啟用了 TPM 2.0。

$ [ -c /dev/tpmrm0 ] && echo "TPM 2.0"
TPM 2.0

當我嘗試安裝時tpm-tools,它給出了以下錯誤:

% sudo apt install tpm-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
tpm-tools is already the newest version (1.3.9.1-0.2ubuntu3).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up trousers (0.3.14+fixed1-1build1) ...
Job for trousers.service failed because the control process exited with error code.
See "systemctl status trousers.service" and "journalctl -xe" for details.
invoke-rc.d: initscript trousers, action "start" failed.
● trousers.service - LSB: starts tcsd
    Loaded: loaded (/etc/init.d/trousers; generated)
    Active: failed (Result: exit-code) since Wed 2021-02-10 03:59:26 AEST; 3ms ago
      Docs: man:systemd-sysv-generator(8)
   Process: 7414 ExecStart=/etc/init.d/trousers start (code=exited, status=30)

Feb 10 03:59:26 blueray-i5 systemd[1]: Starting LSB: starts tcsd...
Feb 10 03:59:26 blueray-i5 trousers[7414]:  * Starting Trusted Computing daemon tcsd
Feb 10 03:59:26 blueray-i5 trousers[7414]: /etc/init.d/trousers: 32: [: /dev/tpm0: unexpected operator
Feb 10 03:59:26 blueray-i5 tcsd[7420]: TCSD TDDL[7420]: TrouSerS ioctl: (25) Inappropriate ioctl for device
Feb 10 03:59:26 blueray-i5 tcsd[7420]: TCSD TDDL[7420]: TrouSerS Falling back to Read/Write device support.
Feb 10 03:59:26 blueray-i5 tcsd[7420]: TCSD TCS[7420]: TrouSerS ERROR: TCS GetCapability failed with result = 0x1e
Feb 10 03:59:26 blueray-i5 trousers[7414]:    ...fail!
Feb 10 03:59:26 blueray-i5 systemd[1]: trousers.service: Control process exited, code=exited, status=30/n/a
Feb 10 03:59:26 blueray-i5 systemd[1]: trousers.service: Failed with result 'exit-code'.
Feb 10 03:59:26 blueray-i5 systemd[1]: Failed to start LSB: starts tcsd.
dpkg: error processing package trousers (--configure):
installed trousers package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of tpm-tools:
tpm-tools depends on trousers; however:
 Package trousers is not configured yet.

dpkg: error processing package tpm-tools (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
trousers
tpm-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)

所以,我嘗試啟動褲子服務。它給出以下消息:

   % systemctl start trousers.service
   Job for trousers.service failed because the control process exited with error code.
   See "systemctl status trousers.service" and "journalctl -xe" for details.
   % systemctl status trousers.service
   ● trousers.service - LSB: starts tcsd
        Loaded: loaded (/etc/init.d/trousers; generated)
        Active: failed (Result: exit-code) since Wed 2021-02-10 04:04:56 AEST; 23s ago
          Docs: man:systemd-sysv-generator(8)
       Process: 9114 ExecStart=/etc/init.d/trousers start (code=exited, status=30)
   
   Feb 10 04:04:56 blueray-i5 systemd[1]: Starting LSB: starts tcsd...
   Feb 10 04:04:56 blueray-i5 trousers[9114]:  * Starting Trusted Computing daemon tcsd
   Feb 10 04:04:56 blueray-i5 trousers[9114]: /etc/init.d/trousers: 32: [: /dev/tpm0: unexpected operator
   Feb 10 04:04:56 blueray-i5 tcsd[9120]: TCSD TDDL[9120]: TrouSerS ioctl: (25) Inappropriate ioctl for device
   Feb 10 04:04:56 blueray-i5 tcsd[9120]: TCSD TDDL[9120]: TrouSerS Falling back to Read/Write device support.
   Feb 10 04:04:56 blueray-i5 tcsd[9120]: TCSD TCS[9120]: TrouSerS ERROR: TCS GetCapability failed with result = 0x1e
   Feb 10 04:04:56 blueray-i5 trousers[9114]:    ...fail!
   Feb 10 04:04:56 blueray-i5 systemd[1]: trousers.service: Control process exited, code=exited, status=30/n/a
   Feb 10 04:04:56 blueray-i5 systemd[1]: trousers.service: Failed with result 'exit-code'.
   Feb 10 04:04:56 blueray-i5 systemd[1]: Failed to start LSB: starts tcsd.

我能做些什麼?

解決 OP在此處發表的評論,他們希望在此處獲取程式碼並將其重寫為更整潔的形式。

我在這裡重複程式碼,以防它從外部站點消失:

   if [ ! -e /dev/tpmrm ]
       then
           log_warning_msg "device driver not loaded, skipping."
           exit 0
       fi

       for tpm_dev in /dev/tpmrm; do
           TPM_OWNER=$(stat -c %U $tpm_dev)
           if [ "x$TPM_OWNER" != "xtss" ]
           then
               log_warning_msg "TPM device owner for $tpm_dev is not 'tss', this can cause problems."
           fi
       done

       if [ ! -e /dev/tpm0 ]
       then
           log_warning_msg "device driver not loaded, skipping."
           exit 0
       fi

       for tpm_dev in /dev/tpm0; do
           TPM_OWNER=$(stat -c %U $tpm_dev)
           if [ "x$TPM_OWNER" != "xtss" ]
           then
               log_warning_msg "TPM device owner for $tpm_dev is not 'tss', this can cause problems."
           fi
       done

整理格式並將其重寫為單個循環:

for tpm_dev in /dev/tpmrm /dev/tpm0; do
   if [ ! -e "$tpm_dev" ]; then
       log_warning_msg "device driver not loaded, skipping."
       continue
   fi

   TPM_OWNER=$(stat -c %U "$tpm_dev")
   if [ "$TPM_OWNER" != "tss" ]; then
       log_warning_msg "TPM device owner for $tpm_dev is not 'tss', this can cause problems."
   fi
done

exit 0如果設備文件不存在,是否仍應執行包含的原始腳本尚不清楚。我選擇使用continue來跳到下一個設備路徑(因為消息說“跳過”)。

我唯一改變的其他事情是x在第二次測試中刪除了過時的安全防護,我添加了一組缺失的雙引號。

或者,沒有continue

for tpm_dev in /dev/tpmrm /dev/tpm0; do
   if [ -e "$tpm_dev" ]; then
       TPM_OWNER=$(stat -c %U "$tpm_dev")
       if [ "$TPM_OWNER" != "tss" ]; then
           log_warning_msg "TPM device owner for $tpm_dev is not 'tss', this can cause problems."
       fi
   else
       log_warning_msg "device driver not loaded, skipping."
   fi
done

引用自:https://unix.stackexchange.com/questions/633563