HTTP/1.1301 Moved Permanently Location: http://www.google.com/ Content-Type: text/html; charset=UTF-8 Cross-Origin-Opener-Policy-Report-Only: same-origin-allow-popups; report-to="gws" Report-To: {"group":"gws","max_age":2592000,"endpoints":[{"url":"https://csp.withgoogle.com/csp/report-to/gws/other"}]} Date: Sat, 07 Jan 2023 07:12:20 GMT Expires: Mon, 06 Feb 2023 07:12:20 GMT Cache-Control: public, max-age=2592000 Server: gws Content-Length: 219 X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN Connection: close
<HTML><HEAD><metahttp-equiv="content-type"content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <AHREF="http://www.google.com/">here</A>. </BODY></HTML>
正是 socket、connect、send、recv 这些简单的系统调用,构筑了 Linux 网络大厦的基石。在 Android 系统上也并无什么不同,无论上层再怎么封装,最终都还是要回归到最基本的系统调用上来
#define AID_INET 3003 /* can create AF_INET and AF_INET6 sockets */
而在 /system/etc/permissions/platform.xml 中也有相应的映射:
1 2 3 4 5 6 7 8 9 10 11 12 13
<permissions> <!-- The following tags are associating low-level group IDs with permission names. By specifying such a mapping, you are saying that any application process granted the given permission will also be running with the given group ID attached to its process, so it can perform any filesystem (read, write, execute) operations allowed for that group. --> ... <permissionname="android.permission.INTERNET"> <groupgid="inet"/> </permission> ... </permissions>
privatestaticvoidspecializeAppProcess(int uid, int gid, int[] gids, int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName, boolean startChildZygote, String instructionSet, String appDataDir, boolean isTopApp, String[] pkgDataInfoList, String[] allowlistedDataInfoList, boolean bindMountAppDataDirs, boolean bindMountAppStorageDirs) { nativeSpecializeAppProcess(uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, startChildZygote, instructionSet, appDataDir, isTopApp, pkgDataInfoList, allowlistedDataInfoList, bindMountAppDataDirs, bindMountAppStorageDirs); // Note that this event ends at the end of handleChildProc. Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "PostFork"); if (gids != null && gids.length > 0) { NetworkUtilsInternal.setAllowNetworkingForProcess(containsInetGid(gids)); } // Set the Java Language thread priority to the default value for new apps. Thread.currentThread().setPriority(Thread.NORM_PRIORITY); /* * This is called here (instead of after the fork but before the specialize) to maintain * consistancy with the code paths for forkAndSpecialize. * * TODO (chriswailes): Look into moving this to immediately after the fork. */ ZygoteHooks.postForkCommon(); }
/** * Allow/Disallow creating AF_INET/AF_INET6 sockets and DNS lookups for current process. * * @param allowNetworking whether to allow or disallow creating AF_INET/AF_INET6 sockets * and DNS lookups. */ publicstaticnativevoidsetAllowNetworkingForProcess(boolean allowNetworking);
/** * sock_create - creates a socket * @family: protocol family (AF_INET, ...) * @type: communication type (SOCK_STREAM, ...) * @protocol: protocol (0, ...) * @res: new socket * * A wrapper around __sock_create(). * Returns 0 or an error. This function internally uses GFP_KERNEL. */
intsock_create(int family, int type, int protocol, struct socket **res) { return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0); }
int __sock_create(struct net *net, int family, int type, int protocol, struct socket **res, int kern) { ... pf = rcu_dereference(net_families[family]); ... err = pf->create(net, sock, protocol, kern); if (err < 0) goto out_module_put; ... }
/** * sock_register - add a socket protocol handler * @ops: description of protocol * * This function is called by a protocol handler that wants to * advertise its address family, and have it linked into the * socket interface. The value ops->family corresponds to the * socket system call protocol family. */ intsock_register(conststruct net_proto_family *ops) { int err;
DEFINE_BPF_PROG_KVER("cgroupsock/inet/create", AID_ROOT, AID_ROOT, inet_socket_create, KVER(4, 14, 0)) (struct bpf_sock* sk) { uint64_t gid_uid = bpf_get_current_uid_gid(); /* * A given app is guaranteed to have the same app ID in all the profiles in * which it is installed, and install permission is granted to app for all * user at install time so we only check the appId part of a request uid at * run time. See UserHandle#isSameApp for detail. */ uint32_t appId = (gid_uid & 0xffffffff) % PER_USER_RANGE; uint8_t* permissions = bpf_uid_permission_map_lookup_elem(&appId); if (!permissions) { // UID not in map. Default to just INTERNET permission. return1; }
// A return value of 1 means allow, everything else means deny. return (*permissions & BPF_PERMISSION_INTERNET) == BPF_PERMISSION_INTERNET; }
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML>