Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5625917ybp; Tue, 8 Oct 2019 06:03:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwnwIqFar7d8x7wSsElEALnMDoXw3bYtXQvz0tl2mFatx3KjvSJrgOq7/4Wp348Baf7xz3 X-Received: by 2002:a17:906:b34c:: with SMTP id cd12mr29015859ejb.48.1570539783368; Tue, 08 Oct 2019 06:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570539783; cv=none; d=google.com; s=arc-20160816; b=BAxNVsznkvyh272ZVRZ2YjhO1WV8vfx3x8Dn/WjHxWPIEYyKmY5nlmFxJm7czibaZc 8mp+2Ft6id/oTHxiPG0k2mvWHUc2rC6dtTLiQn/UjUUwlz9IFjJsfge7X11hI+TkPFJB oPD1k4lvgB+oE2c19O959z92RGZQNMHBBWjiVoMHduJb3vjtGc8Yi/aP9XuQWuILj4qY uCLeGCiOFTbVFFghUT7sWyk4GYkLg0PRAVrVGsd/Z2buh/t/lWMOCoHBrhbRFS6ZVlgi Q8O0VH9PV3GwrrZLtydobLfqk+8dQxPzda/OiB6ultq03WZmEkFo//Iq3ozhBls2agUH Zs+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Wb0R4W0cmsoUcYTNkI1BvCde+djDBComK8vy0RzDClY=; b=NY5MJbElZKKqy7yK1i/kwpcfUIYQOmPF40MukaDczC9zXaU5VDmvJLBRcuT9pvmHy5 Kc9dtAQtAFvtU/GC32YsAiubI1jzEmN6WgsCW7MBs8vboKt3Jk215zbp46TEvjNkwp0V J23EfOKQlSy7MpQqsrM3Y9JXs5TY2ZA2bzVgVlJFhi56btuh80fIU9+/04c3JybTArsL vDZMXwDhK5IKM1+CCkDoDdF7N5hl5706uNucoTx0k5PNF/XqdT12RcOztlzLyzR3lavz DRHebwVM0u/0JJnKsNC/hwJ4NiBk1OTC2a95Rw55QNYX0Vw7zFYQqEVHV8USIQfY4E7V r7Gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z12si8629611ejb.312.2019.10.08.06.02.34; Tue, 08 Oct 2019 06:03:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730923AbfJHNCL (ORCPT + 99 others); Tue, 8 Oct 2019 09:02:11 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54861 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730249AbfJHNCL (ORCPT ); Tue, 8 Oct 2019 09:02:11 -0400 Received: from p2e585ebf.dip0.t-ipconnect.de ([46.88.94.191] helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iHp7t-0001iX-2O; Tue, 08 Oct 2019 13:02:05 +0000 From: Christian Brauner To: jannh@google.com Cc: arve@android.com, christian@brauner.io, devel@driverdev.osuosl.org, gregkh@linuxfoundation.org, joel@joelfernandes.org, linux-kernel@vger.kernel.org, maco@android.com, tkjos@google.com, Christian Brauner , Todd Kjos , Hridya Valsaraju Subject: [PATCH] binder: prevent UAF read in print_binder_transaction_log_entry() Date: Tue, 8 Oct 2019 15:01:59 +0200 Message-Id: <20191008130159.10161-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a binder transaction is initiated on a binder device coming from a binderfs instance, a pointer to the name of the binder device is stashed in the binder_transaction_log_entry's context_name member. Later on it is used to print the name in print_binder_transaction_log_entry(). By the time print_binder_transaction_log_entry() accesses context_name binderfs_evict_inode() might have already freed the associated memory thereby causing a UAF. Do the simple thing and prevent this by copying the name of the binder device instead of stashing a pointer to it. Reported-by: Jann Horn Fixes: 03e2e07e3814 ("binder: Make transaction_log available in binderfs") Link: https://lore.kernel.org/r/CAG48ez14Q0-F8LqsvcNbyR2o6gPW8SHXsm4u5jmD9MpsteM2Tw@mail.gmail.com Cc: Joel Fernandes Cc: Todd Kjos Cc: Hridya Valsaraju Signed-off-by: Christian Brauner --- drivers/android/binder.c | 4 +++- drivers/android/binder_internal.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index c0a491277aca..5b9ac2122e89 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,7 @@ #include #include +#include #include @@ -2876,7 +2878,7 @@ static void binder_transaction(struct binder_proc *proc, e->target_handle = tr->target.handle; e->data_size = tr->data_size; e->offsets_size = tr->offsets_size; - e->context_name = proc->context->name; + strscpy(e->context_name, proc->context->name, BINDERFS_MAX_NAME); if (reply) { binder_inner_proc_lock(proc); diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h index bd47f7f72075..ae991097d14d 100644 --- a/drivers/android/binder_internal.h +++ b/drivers/android/binder_internal.h @@ -130,7 +130,7 @@ struct binder_transaction_log_entry { int return_error_line; uint32_t return_error; uint32_t return_error_param; - const char *context_name; + char context_name[BINDERFS_MAX_NAME + 1]; }; struct binder_transaction_log { -- 2.23.0