Skip to content

Commit 128f380

Browse files
Sherry Yanggregkh
authored andcommitted
android: binder: Rate-limit debug and userspace triggered err msgs
Use rate-limited debug messages where userspace can trigger excessive log spams. Acked-by: Arve Hjønnevåg <[email protected]> Signed-off-by: Sherry Yang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6d33b30 commit 128f380

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

drivers/android/binder.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <linux/pid_namespace.h>
7171
#include <linux/security.h>
7272
#include <linux/spinlock.h>
73+
#include <linux/ratelimit.h>
7374

7475
#include <uapi/linux/android/binder.h>
7576

@@ -163,13 +164,13 @@ module_param_call(stop_on_user_error, binder_set_stop_on_user_error,
163164
#define binder_debug(mask, x...) \
164165
do { \
165166
if (binder_debug_mask & mask) \
166-
pr_info(x); \
167+
pr_info_ratelimited(x); \
167168
} while (0)
168169

169170
#define binder_user_error(x...) \
170171
do { \
171172
if (binder_debug_mask & BINDER_DEBUG_USER_ERROR) \
172-
pr_info(x); \
173+
pr_info_ratelimited(x); \
173174
if (binder_stop_on_user_error) \
174175
binder_stop_on_user_error = 2; \
175176
} while (0)

drivers/android/binder_alloc.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/slab.h>
2828
#include <linux/sched.h>
2929
#include <linux/list_lru.h>
30+
#include <linux/ratelimit.h>
3031
#include <asm/cacheflush.h>
3132
#include "binder_alloc.h"
3233
#include "binder_trace.h"
@@ -36,19 +37,20 @@ struct list_lru binder_alloc_lru;
3637
static DEFINE_MUTEX(binder_alloc_mmap_lock);
3738

3839
enum {
40+
BINDER_DEBUG_USER_ERROR = 1U << 0,
3941
BINDER_DEBUG_OPEN_CLOSE = 1U << 1,
4042
BINDER_DEBUG_BUFFER_ALLOC = 1U << 2,
4143
BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 3,
4244
};
43-
static uint32_t binder_alloc_debug_mask;
45+
static uint32_t binder_alloc_debug_mask = BINDER_DEBUG_USER_ERROR;
4446

4547
module_param_named(debug_mask, binder_alloc_debug_mask,
4648
uint, 0644);
4749

4850
#define binder_alloc_debug(mask, x...) \
4951
do { \
5052
if (binder_alloc_debug_mask & mask) \
51-
pr_info(x); \
53+
pr_info_ratelimited(x); \
5254
} while (0)
5355

5456
static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer)
@@ -152,8 +154,10 @@ static struct binder_buffer *binder_alloc_prepare_to_free_locked(
152154
* free the buffer twice
153155
*/
154156
if (buffer->free_in_progress) {
155-
pr_err("%d:%d FREE_BUFFER u%016llx user freed buffer twice\n",
156-
alloc->pid, current->pid, (u64)user_ptr);
157+
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
158+
"%d:%d FREE_BUFFER u%016llx user freed buffer twice\n",
159+
alloc->pid, current->pid,
160+
(u64)user_ptr);
157161
return NULL;
158162
}
159163
buffer->free_in_progress = 1;
@@ -224,8 +228,9 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
224228
}
225229

226230
if (!vma && need_mm) {
227-
pr_err("%d: binder_alloc_buf failed to map pages in userspace, no vma\n",
228-
alloc->pid);
231+
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
232+
"%d: binder_alloc_buf failed to map pages in userspace, no vma\n",
233+
alloc->pid);
229234
goto err_no_vma;
230235
}
231236

@@ -344,8 +349,9 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
344349
int ret;
345350

346351
if (alloc->vma == NULL) {
347-
pr_err("%d: binder_alloc_buf, no vma\n",
348-
alloc->pid);
352+
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
353+
"%d: binder_alloc_buf, no vma\n",
354+
alloc->pid);
349355
return ERR_PTR(-ESRCH);
350356
}
351357

@@ -417,11 +423,14 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
417423
if (buffer_size > largest_free_size)
418424
largest_free_size = buffer_size;
419425
}
420-
pr_err("%d: binder_alloc_buf size %zd failed, no address space\n",
421-
alloc->pid, size);
422-
pr_err("allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n",
423-
total_alloc_size, allocated_buffers, largest_alloc_size,
424-
total_free_size, free_buffers, largest_free_size);
426+
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
427+
"%d: binder_alloc_buf size %zd failed, no address space\n",
428+
alloc->pid, size);
429+
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
430+
"allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n",
431+
total_alloc_size, allocated_buffers,
432+
largest_alloc_size, total_free_size,
433+
free_buffers, largest_free_size);
425434
return ERR_PTR(-ENOSPC);
426435
}
427436
if (n == NULL) {
@@ -731,8 +740,10 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
731740
err_get_vm_area_failed:
732741
err_already_mapped:
733742
mutex_unlock(&binder_alloc_mmap_lock);
734-
pr_err("%s: %d %lx-%lx %s failed %d\n", __func__,
735-
alloc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
743+
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
744+
"%s: %d %lx-%lx %s failed %d\n", __func__,
745+
alloc->pid, vma->vm_start, vma->vm_end,
746+
failure_string, ret);
736747
return ret;
737748
}
738749

0 commit comments

Comments
 (0)