Linuxカーネルを介してNX CPUビット使用量を確認するには?

Linuxカーネルを介してNX CPUビット使用量を確認するには?

現在のシステムがどのようにNXビット保護を使用しているかを確認したいと思います。dmesg出力の最初の行を確認すると、これを実行できることがわかります。ただし、これはスクロールバッファなので、長期実行システムでは常にこれを行うことはできません。

NX使用量を確認する他の方法はありますか?関連文書を表示できません/proc。ロードされたモジュール(実行ファイルのデータ部分)のメモリマップを確認しようとしましたが、そのモジュールをインポートできる場所が見つかりませんでした。

私はrootこれを確認するために権限を使用しようとしていますが、手動で(これを事前に確認するためにモジュールを書くことができることを知っていますが、それまで行きたくありません)。

ベストアンサー1

長い話を短く

次のコード行を使用してCPUがNX(WikipediaのNXビットに関する追加情報リンク)。

grep -m1 nx /proc/cpuinfo

出力例:

flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d

管理者がカーネルにNX機能を無効にするように指示していないことを確認してください。

grep noexec=off /proc/cmdline

保護がオンの場合は出力があってはなりません。


dmesg唯一の信頼できる方法のようです

ただし、これはCPUがNXをサポートしていることを確認するだけなので、確認することは常により安定していますdmesg

dmesg | grep 'Execute Disable'

次のように出力する必要があります。

[    0.000000] NX (Execute Disable) protection: active

有効、無効

ただし、noexec=offGRUBに追加すると、カーネルのNX機能を無効にできます。

5.4バージョンのカーネルではまだ動作します。

  • /proc/cpuinfoそれでもnx文字列が含まれています

  • dmesgに変更:

    [    0.000000] NX (Execute Disable) protection: disabled by kernel command line option
    
  • journalctl以下を使用することを選択できます。

    journalctl -b | grep 'Execute Disable'
    

スクリプトの確認

Linux用の色

#!/bin/sh

# Wiki: https://en.wikipedia.org/wiki/NX_bit

print_ok__continue () { tput setaf 2 2>/dev/null; tput bold 2>/dev/null; printf '%s: OK\n' "$@"; tput sgr0; }

print_error___exit () { tput setaf 1 2>/dev/null; tput bold 2>/dev/null; printf >&2 '%s\n' "$@"; tput sgr0; exit 1; }

if grep -m1 -q nx /proc/cpuinfo; then
    print_ok__continue '[1]: CPU NX bit is present in your CPU flags'
else
    print_error___exit '[1]: CPU NX bit is missing in your CPU flags'
fi

if ! grep -q noexec=off /proc/cmdline; then
    print_ok__continue '[2]: CPU NX bit is not disabled in GRUB line'
else
    print_error___exit '[2]: CPU NX bit is manually disabled by system administrator via GRUB'
fi

if dmesg | grep -q 'NX (Execute Disable) protection: active'; then
    print_ok__continue '[3]: CPU NX bit is used by your Linux kernel'
else
    print_error___exit '[3]: CPU NX bit is not used by your Linux kernel according to dmesg'
fi

printf '%s\n' 'All tests PASSED, congratulations, you have NX bit capable and enabled CPU + OS!'

おすすめ記事