2012-10-24 3 views
4

netlink 명령을 사용하여 네트워크 인터페이스 (이 경우 socketcan 인터페이스)를 구성하는 JNI 라이브러리를 사용하는 Android 활동이 있습니다. 활동을 실행하면 네트워크 인터페이스 구성이 RTNETLINK의 EPERM 오류로 실패합니다. 실패한 명령은 성공적으로 완료하려면 CAP_NET_ADMIN 기능이 필요합니다. 루트와 같은 코드를 실행하면 루트로 실행되고 루트로 실행 한 다음 CAP_NET_ADMINcapset을 사용하여 기능을 제한합니다. ,CAP_NET_ADMIN 기능으로 실행중인 Android 프로세스를 얻는 방법

<uses-permission android:name="android.permission.INTERNET" />  
<uses-permission android:name="android.permission.NET_ADMIN" /> 

이것은 INETnet_admin 그룹의 과정을 넣어 :

나는 나에게 내 프로세스가 NET_ADMIN 기능을 부여 할 것이다 인상을 준 매니페스트 응용 프로그램에 다음과 같은 권한을 추가 그러나 프로세스가 CAP_NET_ADMIN 기능을받지 못하여 netlink 명령이 EPERM에 실패했습니다.

이 주제에 대한 다양한 검색에서 필자는 기능을 적용해야한다는 힌트를 발견했습니다. 예를 들면, 불행하게도 http://elinux.org/Android_Security

#define    GID  Capability 
AID_NET_BT_ADMIN 3001 Can create an RFCOMM, SCO, or L2CAPP Bluetooth socket 
AID_NET_BT   3002 Can create a Bluetooth socket 
AID_INET   3003 Can create IPv4 or IPv6 socket 
AID_NET_RAW   3004 Can create certain kinds of IPv4 sockets?? 
AID_NET_ADMIN*  3005 Allow CAP_NET_ADMIN permissions for process 

에서이 내 시스템에 적용하지 않는 것 같습니다.

참고 : 시스템 및 커널을 칩셋 공급 업체가 수정하여 실행 중이므로 작동을 멈추게하는 것이 수정되었을 수 있습니다. 이 단지를 작동해야하는 경우

사람이

  • 을 알고 있나요?
  • 프로세스에 기능을 추가하는 데 필요한 다른 단계는 무엇입니까?
  • 여부도 가능합니까?
+0

어떻게 응용 프로그램에 NET_ADMIN 권한을 할당 했습니까? 펌웨어에 사용 된 것과 동일한 키로 서명 되었습니까? Android 4.3 기기에 APK를 설치하는 동안 권한이 삭제되었습니다. java.lang.SecurityException : Permission android.permission.NET_ADMIN은 변경 가능한 권한 타입이 아니다. * 명령은'pm grant android.permission.NET_ADMIN' (루트로서) 에러를 출력한다. – Lekensteyn

+0

내 자신의 질문에 대답하기 위해 새로 작성한 키를 사용하여'/ data'를 닦지 않고 펌웨어를 다시 설치했습니다. 그 결과 여전히 오래된 인증서 ('/ data/system/packages.xml')가 사용되었습니다. 복구 및 재부팅시 4 개의 인증서 (플랫폼, 미디어, 공유, 테스트 키)를 교체 한 후 플랫폼 키를 사용하여 APK에 서명 할 때 권한이 부여되었습니다. – Lekensteyn

답변

4

Android는 그룹 ID를 기반으로 특정 기능을 확인할 수 있도록 커널 기능 시스템을 수정합니다. 불행히도 수정 사항은 모든 경우를 다루는 것으로 보이지 않습니다. 내가 겪고있는 문제를 해결하기 위해 cap_netlink_recvcap_capability 수정 된 Android를 사용하여 확인하십시오. 이를 통해 net_link 그룹의 사용자는 CAP_NET_LINK 기능을 사용할 수 있습니다.

이 변경 사항은 Android 커널에 적용된 수정 사항의 정신에있는 것으로 보이며 내 상황에 적용됩니다.

diff --git a/security/commoncap.c b/security/commoncap.c 
     index ccfe568..f069f8d 100644 
     --- a/security/commoncap.c 
     +++ b/security/commoncap.c 
     @@ -56,21 +56,23 @@ 
    } 
} 

int cap_netlink_send(struct sock *sk, struct sk_buff *skb) 
{ 
» return 0; 
} 

int cap_netlink_recv(struct sk_buff *skb, int cap) 
{ 
-» if (!cap_raised(current_cap(), cap)) 
+» if (cap_capable(current, current_cred(), 
+» » » current_cred()->user->user_ns, cap, 
+» » » SECURITY_CAP_NOAUDIT) != 0) 
» » return -EPERM; 
» return 0; 
} 
EXPORT_SYMBOL(cap_netlink_recv); 

/** 
* cap_capable - Determine whether a task has a particular effective capability 
* @tsk: The task to query 
* @cred: The credentials to use 
* @ns: The user namespace in which we need the capability 
0

실제로, 넷 링크 경로, v3.1-18-gfd77846 이전 커널 버전에 대한 추가 권한 에 대한 검사가 없습니다.

원래 cap_raised을 완전히 바꾸는 것이 좋지 않은 것 같습니다. 따라서 cap_capable에있는 것과 같은 수표를 앞에 붙였습니다.다른 가능한 capCAP_SYS_ADMIN, CAP_AUDIT_CONTROLCAP_AUDIT_WRITE이지만 네트워킹과 관련이 없습니다. 위의 커밋 이후 궁극적으로 cap_capable (capable 통해) 호출 끝납니다.

패치 : 당신이 net_raw 그룹에있을 필요가에 대한 CAP_NET_RAW에서 찾는 사람들에 대해서는

diff --git a/security/commoncap.c b/security/commoncap.c 
index 8bfbd13..485245a 100644 
--- a/security/commoncap.c 
+++ b/security/commoncap.c 
@@ -63,6 +63,10 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb) 

int cap_netlink_recv(struct sk_buff *skb, int cap) 
{ 
+#ifdef CONFIG_ANDROID_PARANOID_NETWORK 
+ if (cap == CAP_NET_ADMIN && in_egroup_p(AID_NET_ADMIN)) 
+  return 0; 
+#endif 
    if (!cap_raised(current_cap(), cap)) 
     return -EPERM; 
    return 0; 

. 이 그룹을 기존 android.permission.NET_ADMIN 권한에 추가하거나 다음 프레임 워크 패치를 적용하십시오.

diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml 
index 1e7dcf7..07f5d94 100644 
--- a/core/res/AndroidManifest.xml 
+++ b/core/res/AndroidManifest.xml 
@@ -927,6 +927,12 @@ 
     android:permissionGroup="android.permission-group.SYSTEM_TOOLS" 
     android:protectionLevel="signature" /> 

+ <!-- Allows access to raw sockets, allowing full network access and spoofing. 
+   @hide --> 
+ <permission android:name="android.permission.NET_RAW" 
+  android:permissionGroup="android.permission-group.SYSTEM_TOOLS" 
+  android:protectionLevel="signature" /> 
+ 
    <!-- Allows registration for remote audio playback. @hide --> 
    <permission android:name="android.permission.REMOTE_AUDIO_PLAYBACK" 
     android:permissionGroup="android.permission-group.SYSTEM_TOOLS" 
diff --git a/data/etc/platform.xml b/data/etc/platform.xml 
index 47cb7ab..9c209c3 100644 
--- a/data/etc/platform.xml 
+++ b/data/etc/platform.xml 
@@ -82,6 +82,10 @@ 
     <group gid="net_admin" /> 
    </permission> 

+ <permission name="android.permission.NET_RAW" > 
+  <group gid="net_raw" /> 
+ </permission> 
+ 
    <!-- The group that /cache belongs to, linked to the permission 
      set on the applications that can access /cache --> 
    <permission name="android.permission.ACCESS_CACHE_FILESYSTEM" >