Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7846959rwb; Wed, 23 Nov 2022 11:33:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf75Le1WWTqTTkB9ZPU6bohvCN4GrqQSoKWQp2gnHfQgQkzyhG7KPFFD7tLydfGbsuvzCeUR X-Received: by 2002:a63:210d:0:b0:43c:1cb8:73ba with SMTP id h13-20020a63210d000000b0043c1cb873bamr8608461pgh.11.1669231997210; Wed, 23 Nov 2022 11:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669231997; cv=none; d=google.com; s=arc-20160816; b=fZN0rnKgsH0E2BH3P0q/3GpE95QNNLorOA+afhNtfqyceMQ9pVRd1iguxBMo60bzSY PcKzQIX88cOUZ0uIXghDitk3lx7W9KnA6PRZvRNOeTdVLwA4tZuq9ZmUHEYf2eln71i6 QPAU6ZEulA/dSa+hvZEB5jC7/eu9QjX5KqDeT1xo7VqyLJhq7IR97J1Da74N+fX7E3N5 X+rep7S2ObtPX5ovGovXWnom0to6UAEYwgq//J4HA30PiyK0vWpFG2wc2idRTxFaRKS8 9Aq/OFqN74UIxKqrinV2RxnFJ00iWtiRfVPiQ6Nj5sFSSflMjrlKPDJn4ja2QeoeHqSk 9LIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6QA+yAL06ySNz02sxUF8x/UDuflnKKFyHryfYiGnxg8=; b=tGGX6UockVUrxYtXq4aG2ewlbPp9MGlyNeVBot8R6YU91TxEAvmfmQrV5AnTUeRCb8 sLI88nHAEqM7mbXRvD46ce59VKT5/Q1blB55/Z6GCKBaRyIzNJdFlYtx73XhH1SLLfqY jWxNNrFWeE54wGPNXTF+SEOSOzb1vflyqeeAmdIM0tbtsggPtmZWgD6UEuQkqLGbwFp3 SoKuXuHUn1LuFz7wuO+L9jaxPrxwdhLh2zKr8RgwtkRh83Dp8t0dtbCIlzxl02kcjDcF iPXDSzeEFq13l4oBK0Tyj+z/mWnEsucSu5KVEzkdSj3EFV05zr3gVcebgPDOqz8Uwtp0 P2tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=q7glId5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j62-20020a638b41000000b004772bd1b7b6si16796485pge.43.2022.11.23.11.33.06; Wed, 23 Nov 2022 11:33:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=q7glId5i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239826AbiKWTML (ORCPT + 88 others); Wed, 23 Nov 2022 14:12:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239688AbiKWTMK (ORCPT ); Wed, 23 Nov 2022 14:12:10 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A58DA1B3 for ; Wed, 23 Nov 2022 11:12:09 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id ci10so10457729pjb.1 for ; Wed, 23 Nov 2022 11:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=6QA+yAL06ySNz02sxUF8x/UDuflnKKFyHryfYiGnxg8=; b=q7glId5iAYE1SXwULrXl4AkDpMcQjOY/W+wshGb4lcJHWA6PW9Ykp0Lt+Isq7gAvwQ aW8ShG/bQafQPXRYYhSjUXKjJznIh6+xq0CGox0p4oFiA2lrSV5KGlt87LD1K3BdDMIp A/42gP/xuewqyX5rkO4iHxsNWiB0GPHzbtnD8qOGI8Q5+CTF8zM+1dE3HC8hNW2Qdsfz zktkj/DynPgD4li9c0O533jKiYDitQFo6lVZuVzNSBOs5PHxhqV1dzg8IJUpC+bZQIxU dhfAh6dVtn8QB6pRq2VGhn7XqI4iMnW5YwQXyVJjxz9SQSwl/vwpApnJ9YATNVTTzbx2 HDPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6QA+yAL06ySNz02sxUF8x/UDuflnKKFyHryfYiGnxg8=; b=qNfg79u38iscxvzRZAiIMxReI1V2WBxyP/GcjM9MU2DbAIQZpqWRK0HHLyeoChnYwC sePUqX+3Keo3aEtegSJdA3XfnhPIrRPK+XlMl16aMcXxEyhd6xBh1H0n39CKHuK0Qvr2 fGvcUgHxB8F1zYRniOmwcFryXZXFmuxUUhu89DcqelKxC9uOZrqjuPBaMw7AC8llSt7Z lonAswYyQyRlx27SXwoQjdKpoXoVW0nJ/cWaF6+YKvuwkpYIbQK2J0JKupBGqKuPwTXn AZANsn0Qs8tVOXmjiKjxs0geXGRBb+cTMiHXjodZAO57PpaSS5Daqxfz14rPgpLt39W2 HlBg== X-Gm-Message-State: ANoB5plZWsjDonEbMqZd3uREanjk0n05gYhJVs4a9Nc7SAc2aAFH41TP oWwibY50YbG27qAc+178FKxyog== X-Received: by 2002:a17:903:2591:b0:179:e1f6:d24d with SMTP id jb17-20020a170903259100b00179e1f6d24dmr9995587plb.91.1669230728649; Wed, 23 Nov 2022 11:12:08 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id lt11-20020a17090b354b00b0020ad86f4c54sm1805746pjb.16.2022.11.23.11.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 11:12:07 -0800 (PST) Date: Wed, 23 Nov 2022 19:12:03 +0000 From: Carlos Llamas To: "Jiazi.Li" Cc: Greg Kroah-Hartman , arve@android.com, Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , "Jiazi.Li" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] binder: remove unneeded size check code Message-ID: References: <20221115120351.2769-1-jiazi.li@transsion.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221115120351.2769-1-jiazi.li@transsion.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 On Tue, Nov 15, 2022 at 08:03:51PM +0800, Jiazi.Li wrote: > In binder_ioctl function, the legitimacy check of cmd size has been > done in switch-case code: > switch (cmd) { > case BINDER_WRITE_READ;//BINDER_WRITE_READ contains size info > > So unneeded do size check in binder_ioctl and binder_ioctl_write_read > again. > > In the following version of Google GKI: > > Linux version 5.10.110-android12-9-00011-g2c814f559132-ab8969555 > > It seems that the compiler has made optimization and has not passed > cmd parameters to binder_ioctl_write_read: > : mov w8, #0x6201 // #25089 > : movk w8, #0xc030, lsl #16 > : cmp w20, w8 > : b.ne 0xffffffda8aa97880 > : mov x0, x23 //filp > : mov x1, x27 //arg > : mov x2, x22 //thread > : bl 0xffffffda8aa9e6e4 > : mov w26, w0 > > Signed-off-by: Jiazi.Li > --- > drivers/android/binder.c | 15 ++------------- > 1 file changed, 2 insertions(+), 13 deletions(-) > > diff --git a/drivers/android/binder.c b/drivers/android/binder.c > index 880224ec6abb..48e5a3531282 100644 > --- a/drivers/android/binder.c > +++ b/drivers/android/binder.c > @@ -5006,20 +5006,14 @@ static __poll_t binder_poll(struct file *filp, > return 0; > } > > -static int binder_ioctl_write_read(struct file *filp, > - unsigned int cmd, unsigned long arg, > +static int binder_ioctl_write_read(struct file *filp, unsigned long arg, > struct binder_thread *thread) > { > int ret = 0; > struct binder_proc *proc = filp->private_data; > - unsigned int size = _IOC_SIZE(cmd); > void __user *ubuf = (void __user *)arg; > struct binder_write_read bwr; > > - if (size != sizeof(struct binder_write_read)) { > - ret = -EINVAL; > - goto out; > - } > if (copy_from_user(&bwr, ubuf, sizeof(bwr))) { > ret = -EFAULT; > goto out; > @@ -5296,7 +5290,6 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > int ret; > struct binder_proc *proc = filp->private_data; > struct binder_thread *thread; > - unsigned int size = _IOC_SIZE(cmd); > void __user *ubuf = (void __user *)arg; > > /*pr_info("binder_ioctl: %d:%d %x %lx\n", > @@ -5318,7 +5311,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > > switch (cmd) { > case BINDER_WRITE_READ: > - ret = binder_ioctl_write_read(filp, cmd, arg, thread); > + ret = binder_ioctl_write_read(filp, arg, thread); > if (ret) > goto err; > break; > @@ -5361,10 +5354,6 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > case BINDER_VERSION: { > struct binder_version __user *ver = ubuf; > > - if (size != sizeof(struct binder_version)) { > - ret = -EINVAL; > - goto err; > - } > if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, > &ver->protocol_version)) { > ret = -EINVAL; > -- > 2.17.1 > Looks good, thanks! Acked-by: Carlos Llamas