Androidカーネルモジュールプログラミング

私はカーネルモジュールをプログラミングしました。このモジュールは、スマートフォンセキュリティのテーマに関する論文の一部です。モジュールはファイルを読み取り、その内容をUDPソケット経由で送信します。

モジュールはUbuntu上で正しく動作しています。右のアンドロイドカーネル(2.6.29)用にコンパイルしました。 Androidの場合:Insmodは正しく動作します。 UDPパケットが受信されると、いくつかのエラーが発生します。 私はそれがファイルの読書と関係があると思う。

まず、すべてのエラーメッセージ:

hiJack: Starting LKM!
hiJack: Sending answer!
hiJack: Reading queue!
hiJack: Opening File!
Unable to handle kernel NULL pointer dereference at virtual address 0000001e
pgd = c0004000
[0000001e] *pgd=00000000
Internal error: Oops: 817 [#1]
Modules linked in: hiJack
CPU: 0    Not tainted  (2.6.29 #3)
PC is at readFile+0x84/0xec [hiJack]
LR is at call_rcu+0x28/0x48
pc : []    lr : []    psr: a0000013
sp : c2a27ef0  ip : 000007ff  fp : c2a27f0c
r10: c2a27f38  r9 : c2a27f1c  r8 : 00000000
r7 : 00000000  r6 : 00000000  r5 : 00000000  r4 : fffffffe
r3 : 00000000  r2 : 00000000  r1 : bf000b38  r0 : fffffffe
Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
Control: 00093177  Table: 02bfc000  DAC: 00000017

LR: 0xc0069e94:
9e94  e5831000 e121f002 e89da810 c02fd2d8 e1a0c00d e92dd830 e24cb004 e5801004
9eb4  e10f4000 e3843080 e121f003 e59f101c e59f201c ebffffc7 e3140080 0a000001
9ed4  e121f004 e89da830 e121f004 e89da830 c02fd2ec c03280ec e1a0c00d e92dd830
9ef4  e24cb004 e5801004 e10f4000 e3843080 e121f003 e59f101c e59f201c ebffffb5
9f14  e3140080 0a000001 e121f004 e89da830 e121f004 e89da830 c02fd2d8 c03280b0
9f34  e1a0c00d e92dd8f0 e24cb004 e5913010 e1a04001 e3530000 e1a05000 0a00004c
9f54  e10f2000 e3823080 e121f003 e5903004 e591100c e0610003 e3500000 a594301c
9f74  a5843014 a5843018 aa000003 e2611001 e1710003 55943018 55843014 e5941014

SP: 0xc2a27e70:
7e70  c2a27e94 c2a27e80 60000013 00000004 c6043430 c0312fb8 ffffffff c2a27edc
7e90  00000000 00000000 c2a27f0c c2a27ea8 c024580c c00221d4 fffffffe bf000b38
7eb0  00000000 00000000 fffffffe 00000000 00000000 00000000 00000000 c2a27f1c
7ed0  c2a27f38 c2a27f0c 000007ff c2a27ef0 c0069f14 bf0000ac a0000013 ffffffff
7ef0  c2a26000 00000000 00000000 c783a2c0 c2a27f7c c2a27f10 bf000170 bf000034
7f10  c024778c bf000b24 c02f201c c6043400 00000017 c02f4e10 c6043400 c02f4f80
7f30  c2a27f54 c2a27f40 c0247814 c0247764 c0312f80 c2a26000 c2a27f9c c2a27f58
7f50  c0243e4c c2988240 c2a26000 bf000114 00000000 00000000 00000000 00000000

FP: 0xc2a27e8c:
7e8c  c2a27edc 00000000 00000000 c2a27f0c c2a27ea8 c024580c c00221d4 fffffffe
7eac  bf000b38 00000000 00000000 fffffffe 00000000 00000000 00000000 00000000
7ecc  c2a27f1c c2a27f38 c2a27f0c 000007ff c2a27ef0 c0069f14 bf0000ac a0000013
7eec  ffffffff c2a26000 00000000 00000000 c783a2c0 c2a27f7c c2a27f10 bf000170
7f0c  bf000034 c024778c bf000b24 c02f201c c6043400 00000017 c02f4e10 c6043400
7f2c  c02f4f80 c2a27f54 c2a27f40 c0247814 c0247764 c0312f80 c2a26000 c2a27f9c
7f4c  c2a27f58 c0243e4c c2988240 c2a26000 bf000114 00000000 00000000 00000000
7f6c  00000000 c2a27f9c c2a27f80 c004aaec bf000120 c2988240 c2a26000 c2a27fa4

R9: 0xc2a27e9c:
7e9c  c2a27ea8 c024580c c00221d4 fffffffe bf000b38 00000000 00000000 fffffffe
7ebc  00000000 00000000 00000000 00000000 c2a27f1c c2a27f38 c2a27f0c 000007ff
7edc  c2a27ef0 c0069f14 bf0000ac a0000013 ffffffff c2a26000 00000000 00000000
7efc  c783a2c0 c2a27f7c c2a27f10 bf000170 bf000034 c024778c bf000b24 c02f201c
7f1c  c6043400 00000017 c02f4e10 c6043400 c02f4f80 c2a27f54 c2a27f40 c0247814
7f3c  c0247764 c0312f80 c2a26000 c2a27f9c c2a27f58 c0243e4c c2988240 c2a26000
7f5c  bf000114 00000000 00000000 00000000 00000000 c2a27f9c c2a27f80 c004aaec
7f7c  bf000120 c2988240 c2a26000 c2a27fa4 c2988248 c2a27fd4 c2a27fa0 c004b1f0

R10: 0xc2a27eb8:
7eb8  fffffffe 00000000 00000000 00000000 00000000 c2a27f1c c2a27f38 c2a27f0c
7ed8  000007ff c2a27ef0 c0069f14 bf0000ac a0000013 ffffffff c2a26000 00000000
7ef8  00000000 c783a2c0 c2a27f7c c2a27f10 bf000170 bf000034 c024778c bf000b24
7f18  c02f201c c6043400 00000017 c02f4e10 c6043400 c02f4f80 c2a27f54 c2a27f40
7f38  c0247814 c0247764 c0312f80 c2a26000 c2a27f9c c2a27f58 c0243e4c c2988240
7f58  c2a26000 bf000114 00000000 00000000 00000000 00000000 c2a27f9c c2a27f80
7f78  c004aaec bf000120 c2988240 c2a26000 c2a27fa4 c2988248 c2a27fd4 c2a27fa0
7f98  c004b1f0 c004aa38 d0fe328e 00000000 c6043400 c004eecc c2a27fb0 c2a27fb0
Process hiJack-workqueu (pid: 305, stack limit = 0xc2a26268)
Stack: (0xc2a27ef0 to 0xc2a28000)
7ee0:                                     c2a26000 00000000 00000000 c783a2c0 
7f00: c2a27f7c c2a27f10 bf000170 bf000034 c024778c bf000b24 c02f201c c6043400 
7f20: 00000017 c02f4e10 c6043400 c02f4f80 c2a27f54 c2a27f40 c0247814 c0247764 
7f40: c0312f80 c2a26000 c2a27f9c c2a27f58 c0243e4c c2988240 c2a26000 bf000114 
7f60: 00000000 00000000 00000000 00000000 c2a27f9c c2a27f80 c004aaec bf000120 
7f80: c2988240 c2a26000 c2a27fa4 c2988248 c2a27fd4 c2a27fa0 c004b1f0 c004aa38 
7fa0: d0fe328e 00000000 c6043400 c004eecc c2a27fb0 c2a27fb0 c2a26000 c004b0ec 
7fc0: c2988240 00000000 c2a27ff4 c2a27fd8 c004e9b0 c004b0f8 00000000 00000000 
7fe0: 00000000 00000000 00000000 c2a27ff8 c003da58 c004e964 00000000 0000001b 
Backtrace: 
[] (readFile+0x0/0xec [hiJack]) from [] (send_answer+0x5c/0x174 [hiJack])
 r7:c783a2c0 r6:00000000 r5:00000000 r4:c2a26000
[] (send_answer+0x0/0x174 [hiJack]) from [] (run_workqueue+0xc0/0x148)
[] (run_workqueue+0x0/0x148) from [] (worker_thread+0x104/0x118)
 r7:c2988248 r6:c2a27fa4 r5:c2a26000 r4:c2988240
[] (worker_thread+0x0/0x118) from [] (kthread+0x58/0x94)
 r7:00000000 r6:c2988240 r5:c004b0ec r4:c2a26000
[] (kthread+0x0/0x94) from [] (do_exit+0x0/0x6e0)
 r7:00000000 r6:00000000 r5:00000000 r4:00000000
Code: ee032f10 e1a02007 e1a03fc2 e59f105c (e1c022f0) 
Kernel panic - not syncing: Fatal exception

誰に何が間違っているのか考えていますか?誰かが私を助けることができれば非常に感謝しています。

これは、エラー処理を追加した後の出力です。

hiJack: Starting LKM!
hiJack: IN Port: 44552
hiJack: Sending answer!
hiJack: Reading queue!
hiJack: Opening File!
Unable to handle kernel paging request at virtual address fffffffe
pgd = c0004000
[fffffffe] *pgd=004a0031, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1]
Modules linked in: hiJack
CPU: 0    Not tainted  (2.6.29 #3)
PC is at send_answer+0x5c/0x198 [hiJack]
LR is at call_rcu+0x28/0x48
pc : []    lr : []    psr: 20000013
sp : c4ef5f10  ip : 00000000  fp : c4ef5f7c
r10: c4ef5f38  r9 : c4ef5f1c  r8 : 00000000
r7 : 00000000  r6 : c28a36a0  r5 : 00000000  r4 : c4ef4000
r3 : 0000000a  r2 : c03280b0  r1 : 00002710  r0 : fffffffe
Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
Control: 00093177  Table: 00d58000  DAC: 00000017

LR: 0xc0069e94:
9e94  e5831000 e121f002 e89da810 c02fd2d8 e1a0c00d e92dd830 e24cb004 e5801004
9eb4  e10f4000 e3843080 e121f003 e59f101c e59f201c ebffffc7 e3140080 0a000001
9ed4  e121f004 e89da830 e121f004 e89da830 c02fd2ec c03280ec e1a0c00d e92dd830
9ef4  e24cb004 e5801004 e10f4000 e3843080 e121f003 e59f101c e59f201c ebffffb5
9f14  e3140080 0a000001 e121f004 e89da830 e121f004 e89da830 c02fd2d8 c03280b0
9f34  e1a0c00d e92dd8f0 e24cb004 e5913010 e1a04001 e3530000 e1a05000 0a00004c
9f54  e10f2000 e3823080 e121f003 e5903004 e591100c e0610003 e3500000 a594301c
9f74  a5843014 a5843018 aa000003 e2611001 e1710003 55943018 55843014 e5941014

SP: 0xc4ef5e90:
5e90  c4ef5ee4 00000001 00000000 c2832ee0 00000000 c28a36a0 ffffffff c4ef5efc
5eb0  c28a36a0 00000000 c4ef5f7c c4ef5ec8 c024580c c00221d4 fffffffe 00002710
5ed0  c03280b0 0000000a c4ef4000 00000000 c28a36a0 00000000 00000000 c4ef5f1c
5ef0  c4ef5f38 c4ef5f7c 00000000 c4ef5f10 c0069f14 bf00017c 20000013 ffffffff
5f10  c024778c bf000b94 c4eb801c c59fa400 00000015 c02f4e10 c59fa400 c5dc8000
5f30  c4ef5f54 c4ef5f40 c0247814 c0247764 c0312f80 c4ef4000 c4ef5f9c c4ef5f58
5f50  c0243e4c c2816d60 c4ef4000 bf000120 00000000 00000000 00000000 00000000
5f70  c4ef5f9c c4ef5f80 c004aaec bf00012c c2816d60 c4ef4000 c4ef5fa4 c2816d68

FP: 0xc4ef5efc:
5efc  c4ef5f10 c0069f14 bf00017c 20000013 ffffffff c024778c bf000b94 c4eb801c
5f1c  c59fa400 00000015 c02f4e10 c59fa400 c5dc8000 c4ef5f54 c4ef5f40 c0247814
5f3c  c0247764 c0312f80 c4ef4000 c4ef5f9c c4ef5f58 c0243e4c c2816d60 c4ef4000
5f5c  bf000120 00000000 00000000 00000000 00000000 c4ef5f9c c4ef5f80 c004aaec
5f7c  bf00012c c2816d60 c4ef4000 c4ef5fa4 c2816d68 c4ef5fd4 c4ef5fa0 c004b1f0
5f9c  c004aa38 455b97e6 00000000 c59fa400 c004eecc c4ef5fb0 c4ef5fb0 c4ef4000
5fbc  c004b0ec c2816d60 00000000 c4ef5ff4 c4ef5fd8 c004e9b0 c004b0f8 00000000
5fdc  00000000 00000000 00000000 00000000 c4ef5ff8 c003da58 c004e964 011a5412

R2: 0xc0328030:
8030  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8050  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8070  00000000 00000001 00000001 00000000 00000000 00000000 00000000 00000000
8090  00000000 00000000 00000000 00000000 00000000 00000000 00000000 c7810f60
80b0  00000724 00000001 00000000 00000725 c7cbe650 c03280c0 c37cc3c0 c2832ee0
80d0  0000000a 00000000 c03280d4 0000000a 00000000 00000000 00000000 fffffed4
80f0  00000001 00000000 00000000 00000000 c03280fc c03280fc c03280fc 00000000
8110  00000000 c0328110 0000000a 00000000 00000000 00000000 00000000 00008000

R4: 0xc4ef3f80:
3f80  00000008 00000000 44feb4b8 00000000 44feb460 44faefe8 00000000 44fe7fa0
3fa0  00000000 44feb420 006e0061 00000023 4000d1c8 00000000 44faefd0 00000bd7
3fc0  00000000 00000002 00630069 0000001b 4000d520 00000000 00000002 00000000
3fe0  0075005e 00000023 4000de90 00000000 44faefb0 44fec230 00000000 79926933
4000  00000002 00000001 00000000 c59fa400 c02f6d08 00000000 00000017 c0312f80
4020  c4ef4000 00000420 c02f4e10 c59fa400 c6468240 c5dc8000 c4ef5f9c c4ef5f58
4040  c0243e48 00000000 00000000 00000000 00000000 00000000 00000000 00000000
4060  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

R6: 0xc28a3620:
3620  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
3640  00000000 00000000 00000000 c01b4b08 00000000 00000000 00000000 00000000
3660  00000000 00000000 00000000 c2920a23 c2920a40 c2920a00 c2920a23 000000e8
3680  00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000
36a0  00000000 00000000 c7b89b80 00000000 00000000 00000000 00000000 c3d46b80
36c0  00000000 00000000 00000000 00000000 00000000 00000011 00000000 00000000
36e0  00000000 00000000 00000000 00000000 00000000 00000011 00000000 0000000e
3700  00060024 00000000 0008000d c01b2ef8 00000001 00000000 00000000 00000000

R9: 0xc4ef5e9c:
5e9c  c2832ee0 00000000 c28a36a0 ffffffff c4ef5efc c28a36a0 00000000 c4ef5f7c
5ebc  c4ef5ec8 c024580c c00221d4 fffffffe 00002710 c03280b0 0000000a c4ef4000
5edc  00000000 c28a36a0 00000000 00000000 c4ef5f1c c4ef5f38 c4ef5f7c 00000000
5efc  c4ef5f10 c0069f14 bf00017c 20000013 ffffffff c024778c bf000b94 c4eb801c
5f1c  c59fa400 00000015 c02f4e10 c59fa400 c5dc8000 c4ef5f54 c4ef5f40 c0247814
5f3c  c0247764 c0312f80 c4ef4000 c4ef5f9c c4ef5f58 c0243e4c c2816d60 c4ef4000
5f5c  bf000120 00000000 00000000 00000000 00000000 c4ef5f9c c4ef5f80 c004aaec
5f7c  bf00012c c2816d60 c4ef4000 c4ef5fa4 c2816d68 c4ef5fd4 c4ef5fa0 c004b1f0

R10: 0xc4ef5eb8:
5eb8  c4ef5f7c c4ef5ec8 c024580c c00221d4 fffffffe 00002710 c03280b0 0000000a
5ed8  c4ef4000 00000000 c28a36a0 00000000 00000000 c4ef5f1c c4ef5f38 c4ef5f7c
5ef8  00000000 c4ef5f10 c0069f14 bf00017c 20000013 ffffffff c024778c bf000b94
5f18  c4eb801c c59fa400 00000015 c02f4e10 c59fa400 c5dc8000 c4ef5f54 c4ef5f40
5f38  c0247814 c0247764 c0312f80 c4ef4000 c4ef5f9c c4ef5f58 c0243e4c c2816d60
5f58  c4ef4000 bf000120 00000000 00000000 00000000 00000000 c4ef5f9c c4ef5f80
5f78  c004aaec bf00012c c2816d60 c4ef4000 c4ef5fa4 c2816d68 c4ef5fd4 c4ef5fa0
5f98  c004b1f0 c004aa38 455b97e6 00000000 c59fa400 c004eecc c4ef5fb0 c4ef5fb0
Process hiJack-workqueu (pid: 269, stack limit = 0xc4ef4268)
Stack: (0xc4ef5f10 to 0xc4ef6000)
5f00:                                     c024778c bf000b94 c4eb801c c59fa400 
5f20: 00000015 c02f4e10 c59fa400 c5dc8000 c4ef5f54 c4ef5f40 c0247814 c0247764 
5f40: c0312f80 c4ef4000 c4ef5f9c c4ef5f58 c0243e4c c2816d60 c4ef4000 bf000120 
5f60: 00000000 00000000 00000000 00000000 c4ef5f9c c4ef5f80 c004aaec bf00012c 
5f80: c2816d60 c4ef4000 c4ef5fa4 c2816d68 c4ef5fd4 c4ef5fa0 c004b1f0 c004aa38 
5fa0: 455b97e6 00000000 c59fa400 c004eecc c4ef5fb0 c4ef5fb0 c4ef4000 c004b0ec 
5fc0: c2816d60 00000000 c4ef5ff4 c4ef5fd8 c004e9b0 c004b0f8 00000000 00000000 
5fe0: 00000000 00000000 00000000 c4ef5ff8 c003da58 c004e964 011a5412 10f80005 
Backtrace: 
[] (send_answer+0x0/0x198 [hiJack]) from [] (run_workqueue+0xc0/0x148)
[] (run_workqueue+0x0/0x148) from [] (worker_thread+0x104/0x118)
 r7:c2816d68 r6:c4ef5fa4 r5:c4ef4000 r4:c2816d60
[] (worker_thread+0x0/0x118) from [] (kthread+0x58/0x94)
 r7:00000000 r6:c2816d60 r5:c004b0ec r4:c4ef4000
[] (kthread+0x0/0x94) from [] (do_exit+0x0/0x6e0)
 r7:00000000 r6:00000000 r5:00000000 r4:00000000
Code: eb490d30 e1a01005 e59f0124 ebffffaa (e5d03000) 
Kernel panic - not syncing: Fatal exception

ありがとうございました!

2
良い答えが見つかった後に質問の重要な部分を編集することはうまくいかない。
追加された 著者 dmeister,

2 答え

次の呼び出しの前後でエラーチェックを行う価値があります。


phMscd_Filp = filp_open(filename, O_RDONLY, 0);

...結果のポインタを間接参照しようとする前に...。

filp_open()から返される値は、 IS_ERR()マクロを使用してチェックする必要があります。 たとえば、 fs/reiserfs/journal.c ファイルから:


journal->j_dev_file = filp_open(jdev_name, 0, 0);
if(!IS_ERR(journal->j_dev_file)) {
 //snip
} else {
  result = PTR_ERR(journal->j_dev_file);
 //dump a warning using the return code
}
1
追加された
しかし、ファイルが存在するので、私は読んでみたいと思います...ここでどのようにエラーをキャッチすることができますか?迅速なご回答をありがとうございました!
追加された 著者 bloxtr,
こんにちは、私は今、エラー処理をインストールしました。私はまだエラーが発生します。たぶん誰かがこの問題を解決する別のアイデアを持っています。ありがとうございました ..
追加された 著者 bloxtr,

私は間違いを見つけて笑わないでください!パスが保存されている文字列をチェックしてください:D

0
追加された
コードはどこですか?
追加された 著者 shunty,