Skip to content

Commit 17e7637

Browse files
committed
Merge tag 'char-misc-4.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver fixes from Greg KH: "Here are four small fixes for 4.14-rc6. Three of them are binder driver fixes for reported issues, and the last one is a hyperv driver bugfix. Nothing major, but good fixes to get into 4.14-final. All of these have been in linux-next with no reported issues" * tag 'char-misc-4.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: android: binder: Fix null ptr dereference in debug msg android: binder: Don't get mm from task vmbus: hvsock: add proper sync for vmbus_hvsock_device_unregister() binder: call poll_wait() unconditionally.
2 parents 5805992 + ae65c85 commit 17e7637

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

drivers/android/binder.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,12 +3662,6 @@ static void binder_stat_br(struct binder_proc *proc,
36623662
}
36633663
}
36643664

3665-
static int binder_has_thread_work(struct binder_thread *thread)
3666-
{
3667-
return !binder_worklist_empty(thread->proc, &thread->todo) ||
3668-
thread->looper_need_return;
3669-
}
3670-
36713665
static int binder_put_node_cmd(struct binder_proc *proc,
36723666
struct binder_thread *thread,
36733667
void __user **ptrp,
@@ -4297,12 +4291,9 @@ static unsigned int binder_poll(struct file *filp,
42974291

42984292
binder_inner_proc_unlock(thread->proc);
42994293

4300-
if (binder_has_work(thread, wait_for_proc_work))
4301-
return POLLIN;
4302-
43034294
poll_wait(filp, &thread->wait, wait);
43044295

4305-
if (binder_has_thread_work(thread))
4296+
if (binder_has_work(thread, wait_for_proc_work))
43064297
return POLLIN;
43074298

43084299
return 0;

drivers/android/binder_alloc.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,12 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
215215
}
216216
}
217217

218-
if (!vma && need_mm)
219-
mm = get_task_mm(alloc->tsk);
218+
if (!vma && need_mm && mmget_not_zero(alloc->vma_vm_mm))
219+
mm = alloc->vma_vm_mm;
220220

221221
if (mm) {
222222
down_write(&mm->mmap_sem);
223223
vma = alloc->vma;
224-
if (vma && mm != alloc->vma_vm_mm) {
225-
pr_err("%d: vma mm and task mm mismatch\n",
226-
alloc->pid);
227-
vma = NULL;
228-
}
229224
}
230225

231226
if (!vma && need_mm) {
@@ -565,7 +560,7 @@ static void binder_delete_free_buffer(struct binder_alloc *alloc,
565560
binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
566561
"%d: merge free, buffer %pK do not share page with %pK or %pK\n",
567562
alloc->pid, buffer->data,
568-
prev->data, next->data);
563+
prev->data, next ? next->data : NULL);
569564
binder_update_page_range(alloc, 0, buffer_start_page(buffer),
570565
buffer_start_page(buffer) + PAGE_SIZE,
571566
NULL);
@@ -720,6 +715,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
720715
barrier();
721716
alloc->vma = vma;
722717
alloc->vma_vm_mm = vma->vm_mm;
718+
mmgrab(alloc->vma_vm_mm);
723719

724720
return 0;
725721

@@ -795,6 +791,8 @@ void binder_alloc_deferred_release(struct binder_alloc *alloc)
795791
vfree(alloc->buffer);
796792
}
797793
mutex_unlock(&alloc->mutex);
794+
if (alloc->vma_vm_mm)
795+
mmdrop(alloc->vma_vm_mm);
798796

799797
binder_alloc_debug(BINDER_DEBUG_OPEN_CLOSE,
800798
"%s: %d buffers %d, pages %d\n",
@@ -889,7 +887,6 @@ int binder_alloc_get_allocated_count(struct binder_alloc *alloc)
889887
void binder_alloc_vma_close(struct binder_alloc *alloc)
890888
{
891889
WRITE_ONCE(alloc->vma, NULL);
892-
WRITE_ONCE(alloc->vma_vm_mm, NULL);
893890
}
894891

895892
/**
@@ -926,9 +923,9 @@ enum lru_status binder_alloc_free_page(struct list_head *item,
926923
page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE;
927924
vma = alloc->vma;
928925
if (vma) {
929-
mm = get_task_mm(alloc->tsk);
930-
if (!mm)
931-
goto err_get_task_mm_failed;
926+
if (!mmget_not_zero(alloc->vma_vm_mm))
927+
goto err_mmget;
928+
mm = alloc->vma_vm_mm;
932929
if (!down_write_trylock(&mm->mmap_sem))
933930
goto err_down_write_mmap_sem_failed;
934931
}
@@ -963,7 +960,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item,
963960

964961
err_down_write_mmap_sem_failed:
965962
mmput_async(mm);
966-
err_get_task_mm_failed:
963+
err_mmget:
967964
err_page_already_freed:
968965
mutex_unlock(&alloc->mutex);
969966
err_get_alloc_mutex_failed:
@@ -1002,7 +999,6 @@ struct shrinker binder_shrinker = {
1002999
*/
10031000
void binder_alloc_init(struct binder_alloc *alloc)
10041001
{
1005-
alloc->tsk = current->group_leader;
10061002
alloc->pid = current->group_leader->pid;
10071003
mutex_init(&alloc->mutex);
10081004
INIT_LIST_HEAD(&alloc->buffers);

drivers/android/binder_alloc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ struct binder_lru_page {
100100
*/
101101
struct binder_alloc {
102102
struct mutex mutex;
103-
struct task_struct *tsk;
104103
struct vm_area_struct *vma;
105104
struct mm_struct *vma_vm_mm;
106105
void *buffer;

drivers/hv/channel_mgmt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,10 @@ void vmbus_hvsock_device_unregister(struct vmbus_channel *channel)
937937
{
938938
BUG_ON(!is_hvsock_channel(channel));
939939

940-
channel->rescind = true;
940+
/* We always get a rescind msg when a connection is closed. */
941+
while (!READ_ONCE(channel->probe_done) || !READ_ONCE(channel->rescind))
942+
msleep(1);
943+
941944
vmbus_device_unregister(channel->device_obj);
942945
}
943946
EXPORT_SYMBOL_GPL(vmbus_hvsock_device_unregister);

0 commit comments

Comments
 (0)