Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp119440iob; Tue, 17 May 2022 20:52:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdI1d34BH09q2s6n68DSXz4Wlns3jfGCJSWj/ZuJST94yXu8LwOLflZQuwiLssaVRHHDyK X-Received: by 2002:a63:c147:0:b0:3f5:f6f5:fe0e with SMTP id p7-20020a63c147000000b003f5f6f5fe0emr1834359pgi.501.1652845928540; Tue, 17 May 2022 20:52:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845928; cv=none; d=google.com; s=arc-20160816; b=IZtT0zdhUpP3MFQ36oAYyIh3VBVU8RsO9t5Nphe6rs+Y0LvaXYuuHIbRdoMl2TJRGr Qvz1k+pedP/dql3Wk+9LSd7N0TkJRATaBF+Pwvc8ePy0PLZY2DuFZmvgKuG3x5m993Mo aoNMz8ZNH8eFD2DOhXoT+9GSNCcRBWbW0qPEsDz78aadORNmRxh1nAe/xoeZw5X5Is+k eYfUfVE+fPaYQGJcOK8wqOr0u5B6+Rn9gHRjJqp69KMd5sLYYfJBF3PMv8FZOG5W1fan XPA4xVqb1F7QPuppGIteks6v/Qrcgl5j/J2IzbD1oJwdFGS5RB8LOMsnmWTwsPAD9wfd 0xTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uMFc8C/CfVChmB1k26kuQbqCm1tMkQ9Uj/R/VPJ8nN4=; b=jY20EAOEGyOemqRiae03mH4JcFe5tfCVSZ+9EBkAy6kcqNui1jVms+B5AvWEJzSn2L pZDMP/NXLOQBCWGK8jZjrOAhX/srwVO1/OPiUp1mTzjrbK8WijvH2qgVwtdUYgU3Iv+7 Ow+K2Cm5JQrF/7fGtC59iGj68kivCgjl75EqRpr1JZW0MtaGvJaGVoEGIMDwHERvUUPb qHtWqSlyHLd1GirgYNRVQEGVyq0SaGKl7cAFhkyxDsqxFXAbtg/06Fj1490DVHEb93Qq gmf9M3q9vcYphWUknrreL6JT042RSL4c+3D45N+8F4a9CW6YShQykVNCxfPTYMJGg30Y +6Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K9IM4iqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w6-20020a056a0014c600b0050d1e1735aasi1700400pfu.191.2022.05.17.20.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:52:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=K9IM4iqh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE10E9155B; Tue, 17 May 2022 20:34:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233620AbiERBaA (ORCPT + 99 others); Tue, 17 May 2022 21:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbiERB36 (ORCPT ); Tue, 17 May 2022 21:29:58 -0400 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31EE354690 for ; Tue, 17 May 2022 18:29:57 -0700 (PDT) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-f1d5464c48so873427fac.6 for ; Tue, 17 May 2022 18:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uMFc8C/CfVChmB1k26kuQbqCm1tMkQ9Uj/R/VPJ8nN4=; b=K9IM4iqhrgC99GwHjRJavKT4ovzTwZsP4J81tTZ5GLRGhVcKqkKMimqYmOakkBmwu/ vf4681g3GRq3Xc2cfKiHiZt8ac27ctn7HZkgvLZtJtd19qJgE1REzPAeCaglz2Xsjm+Z hpMSUgV30i6zW6HEspZ7jjooAlYGKfmPs04nRKRSdGPTkS/2Awa2hINB5530zcO8XLy3 TcmmtYkyOyFxSdpMCkodIXLG5zYsMC1GQqwtKogb7Xi6F138TeSGHbvI07V/fy4W5w7u Y4sJY1mnfaOUa9cf+kv1/qNYe6r8PPM8C+7SXI8haCw+PNtdyhyOWviTEfduyTxkU6IS 9LhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uMFc8C/CfVChmB1k26kuQbqCm1tMkQ9Uj/R/VPJ8nN4=; b=3HIlWworqJVkWftznX+BSqu1wrfreADX24lXZpUZame+YIeaUvTTpTAW2Dm+wHqlwa ncRdSL4LU1WNj353uuo4iPPYtnEX4hMwYfoCwF6DzDDh7eH3NAOMC5vXijb2H4fHa4qT 6UdjrnAaZngA8VDeN+/jIvPBRJBrCgjibGibdfHs7/dAZs5NnFTnWXzhiFCFJbpNjA40 2cphqMEszsogmGPXC5wS/eDFnsFbN6yNUgVQmHdgP3UbLwREaM4CS8uAOg+RTHfyt6Ku ZVkzBJq8i0w4c8zIJ18gx1FH7HfgEtDPfzwcEAfvUlWjko2uOOTX4mDWq0YQF6BP5GGh MBww== X-Gm-Message-State: AOAM531Y9cs9hP7gkRTSBtKBexsi1mFNvIUQFVYISXA7XagCnnOZzpYs Qm4tiJWGI1bPbBZ6FC9cwuW3Dc6DVeSi6swbW4R8i9dH54I3EA== X-Received: by 2002:a05:6870:8a0b:b0:f1:8e74:261f with SMTP id p11-20020a0568708a0b00b000f18e74261fmr9260911oaq.276.1652837396518; Tue, 17 May 2022 18:29:56 -0700 (PDT) MIME-Version: 1.0 References: <20220517175225.65283-1-schspa@gmail.com> In-Reply-To: From: Schspa Shi Date: Wed, 18 May 2022 09:29:45 +0800 Message-ID: Subject: Re: [PATCH] binder: fix atomic sleep when get extended error To: Carlos Llamas Cc: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, maco@android.com, joel@joelfernandes.org, brauner@kernel.org, hridya@google.com, surenb@google.com, linux-kernel@vger.kernel.org, syzbot+46fff6434a7f968ecb39@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Carlos Llamas writes: > On Wed, May 18, 2022 at 01:52:25AM +0800, Schspa Shi wrote: >> binder_inner_proc_lock(thread->proc) is a spin lock, copy_to_user can't >> be called with in this lock. >> >> Copy it as a local variable, and check the id to make sure the user space >> gets the latest error message >> >> Reported-by: syzbot+46fff6434a7f968ecb39@syzkaller.appspotmail.com >> Fixes: bd32889e841c ("binder: add BINDER_GET_EXTENDED_ERROR ioctl") >> Signed-off-by: Schspa Shi >> --- >> drivers/android/binder.c | 13 ++++++++++--- >> 1 file changed, 10 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/android/binder.c b/drivers/android/binder.c >> index d9253b2a7bd9..5f2e1fa3da74 100644 >> --- a/drivers/android/binder.c >> +++ b/drivers/android/binder.c >> @@ -5163,13 +5163,20 @@ static int binder_ioctl_get_extended_error(struct binder_thread *thread, >> void __user *ubuf) >> { >> struct binder_extended_error *ee = &thread->ee; >> + struct binder_extended_error eeb; >> >> binder_inner_proc_lock(thread->proc); >> - if (copy_to_user(ubuf, ee, sizeof(*ee))) { >> - binder_inner_proc_unlock(thread->proc); >> +retry: >> + eeb = *ee; >> + binder_inner_proc_unlock(thread->proc); >> + if (copy_to_user(ubuf, &eeb, sizeof(eeb))) >> return -EFAULT; >> - } >> >> + binder_inner_proc_lock(thread->proc); >> + if (eeb.id != ee->id) { >> + /* retry to get newest error info */ >> + goto retry; >> + } >> ee->id = 0; >> ee->command = BR_OK; >> ee->param = 0; >> -- >> 2.24.3 (Apple Git-128) >> > > Oops! Thank you for your patch. In this case the local copy would be > enough, no need for the retry logic as this is already taken care of. > You could also leverage the binder_set_extended_error() to reset the > thread->ee. Would you mind sending these updates? I was thinking > something like this: Yes, I have sent a v2 patch for this, please review it. > > drivers/android/binder.c | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > index 83facfa1a5c3..f92021cd384b 100644 > --- a/drivers/android/binder.c > +++ b/drivers/android/binder.c > @@ -5163,19 +5163,16 @@ static int binder_ioctl_get_freezer_info( > static int binder_ioctl_get_extended_error(struct binder_thread *thread, > void __user *ubuf) > { > - struct binder_extended_error *ee = &thread->ee; > + struct binder_extended_error ee; > > binder_inner_proc_lock(thread->proc); > - if (copy_to_user(ubuf, ee, sizeof(*ee))) { > - binder_inner_proc_unlock(thread->proc); > - return -EFAULT; > - } > - > - ee->id = 0; > - ee->command = BR_OK; > - ee->param = 0; > + ee = thread->ee; > + binder_set_extended_error(&thread->ee, 0, BR_OK, 0); > binder_inner_proc_unlock(thread->proc); > > + if (copy_to_user(ubuf, &ee, sizeof(ee))) > + return -EFAULT; > + > return 0; > } -- BRs Schspa Shi