Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp118532rwb; Tue, 27 Sep 2022 23:41:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wA/ICeNkVovB9utz+Pmuc8ahPFum+wu79WWk3qqFSP9s2FEDPmWDIxFpvllqjqyljFpwu X-Received: by 2002:a17:907:2bdd:b0:77d:e0f3:81e5 with SMTP id gv29-20020a1709072bdd00b0077de0f381e5mr26286329ejc.328.1664347314052; Tue, 27 Sep 2022 23:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664347314; cv=none; d=google.com; s=arc-20160816; b=upSPYsIHzOhQ6IQqD9SaCaW1PTEmn59xKnUOzOIhqsspe1r/fbZV6uo8FENeGK4/5B bNxmT4h2AmUqFJT7+voXJ0jUR7VPfvUQRYTXI2t/W3T43CPPVOIkrzvjoj9VlJSJnADr IaPXh/zjFmGSqd2xQfvs0uDFfXkLLWyDxjNY49LGlyiYKPJ6RR4WybwDvhr0DPB+hWpn KgQi77VHnXRxWF+tG6+K26ZXV2PnBsFh7fvDaRekp0kJhnHg2qkGVPvJ4D+IcLa0Ldyl LxeKfE/PJ3/rwA33jMVHA3SSXwYUzKFdS9zMJaBorh73URyKidk+k0BChdh4hOt66t2V sM6g== 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=H7MUjxOP9A0xjlw75Cny+BBP2O6qlasSblRZfxpbCkc=; b=LRGNxuzznISa6026H4LH+HLlx3SV2sSF94hqE+HYu1tftsYVrA/IYL6DL97agxyeKw rQCt4H1rTS+rCP1Adgrxd5kETO6FYpZEcsAe0RM28iQ6FGs9yUAdbiWUlsH/QZP37dEx 0LKya7bxlLKm90Sjad7QA88DoEDOpVAeI8fcT2SK6rxC/VBP+Jooepm0ynxTThEG31Au 4zJyXmZnfUgT+SCCiyqLc51JJ0SQt7ZyUIpMJj4rgq20EANO0gyfEjzBatlsqZomLOEa M7kwrFHD+ZPCv/ZZ7ruF/INUhN2SAh9d5gno/56bRulrddU0+U8aWe/AMeZyXZ/LFvIy mrfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="BzSjbd/B"; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n23-20020a509357000000b00450f56cd37bsi430544eda.175.2022.09.27.23.41.28; Tue, 27 Sep 2022 23:41:54 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="BzSjbd/B"; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232333AbiI1GYj (ORCPT + 99 others); Wed, 28 Sep 2022 02:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232496AbiI1GYi (ORCPT ); Wed, 28 Sep 2022 02:24:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC33DFF3 for ; Tue, 27 Sep 2022 23:24:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B3FA36153A for ; Wed, 28 Sep 2022 06:24:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 742D5C433C1; Wed, 28 Sep 2022 06:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664346275; bh=mMGxrGfWQSTWKf4BUqqAv+XaCxIpAiAlywLKwbZvSzA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BzSjbd/BF8kdkDJVJtpRVSmX0BirsIiyiDYcmQ6hGrBipEevM62ZNxrCN3Jr/27qz oHc48+tveBVqmurGHWi+csfDE36lkzhAN5QDeiBfZazUSm6H6GT392rZllAC9OoE/8 kzqI30lbMghxaWvQzVxFlp1d9cOJASbJMJZzGYNY= Date: Wed, 28 Sep 2022 08:25:09 +0200 From: Greg KH To: Zheng Wang Cc: dimitri.sivanich@hpe.com, arnd@arndb.de, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, alex000young@gmail.com, security@kernel.org Subject: Re: [PATCH] misc: sgi-gru: fix use after free bugs in gru_set_context_option, gru_fault and gru_handle_user_call_os Message-ID: References: <20220928025957.1050698-1-zyytlz.wz@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220928025957.1050698-1-zyytlz.wz@163.com> X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Wed, Sep 28, 2022 at 10:59:57AM +0800, Zheng Wang wrote: > Gts may be freed in gru_check_chiplet_assignment. > The caller still use it after that, UAF happens. > > Fix it by introducing a return value to see if it's in error path or not. > Free the gts in caller if gru_check_chiplet_assignment check failed. > > Fixes: 55484c45dbec ("gru: allow users to specify gru chiplet 2") > Reported-by: Zheng Wang > Signed-off-by: Zheng Wang > > --- > drivers/misc/sgi-gru/grufault.c | 14 ++++++++++++-- > drivers/misc/sgi-gru/grumain.c | 17 +++++++++++++---- > drivers/misc/sgi-gru/grutables.h | 2 +- > 3 files changed, 26 insertions(+), 7 deletions(-) > > diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c > index d7ef61e602ed..2b5b049fbd38 100644 > --- a/drivers/misc/sgi-gru/grufault.c > +++ b/drivers/misc/sgi-gru/grufault.c > @@ -656,7 +656,9 @@ int gru_handle_user_call_os(unsigned long cb) > if (ucbnum >= gts->ts_cbr_au_count * GRU_CBR_AU_SIZE) > goto exit; > > - gru_check_context_placement(gts); > + ret = gru_check_context_placement(gts); > + if (ret) > + goto err; > > /* > * CCH may contain stale data if ts_force_cch_reload is set. > @@ -677,6 +679,10 @@ int gru_handle_user_call_os(unsigned long cb) > exit: > gru_unlock_gts(gts); > return ret; > +err: > + gru_unlock_gts(gts); > + gru_unload_context(gts, 1); > + return -EINVAL; > } > > /* > @@ -874,7 +880,7 @@ int gru_set_context_option(unsigned long arg) > } else { > gts->ts_user_blade_id = req.val1; > gts->ts_user_chiplet_id = req.val0; > - gru_check_context_placement(gts); > + ret = gru_check_context_placement(gts); > } > break; > case sco_gseg_owner: > @@ -889,6 +895,10 @@ int gru_set_context_option(unsigned long arg) > ret = -EINVAL; > } > gru_unlock_gts(gts); > + if (ret) { > + gru_unload_context(gts, 1); > + ret = -EINVAL; > + } > > return ret; > } > diff --git a/drivers/misc/sgi-gru/grumain.c b/drivers/misc/sgi-gru/grumain.c > index 9afda47efbf2..79903cf7e706 100644 > --- a/drivers/misc/sgi-gru/grumain.c > +++ b/drivers/misc/sgi-gru/grumain.c > @@ -716,9 +716,10 @@ static int gru_check_chiplet_assignment(struct gru_state *gru, > * chiplet. Misassignment can occur if the process migrates to a different > * blade or if the user changes the selected blade/chiplet. > */ > -void gru_check_context_placement(struct gru_thread_state *gts) > +int gru_check_context_placement(struct gru_thread_state *gts) > { > struct gru_state *gru; > + int ret = 0; > > /* > * If the current task is the context owner, verify that the > @@ -727,14 +728,16 @@ void gru_check_context_placement(struct gru_thread_state *gts) > */ > gru = gts->ts_gru; > if (!gru || gts->ts_tgid_owner != current->tgid) > - return; > + return ret; > > if (!gru_check_chiplet_assignment(gru, gts)) { > STAT(check_context_unload); > - gru_unload_context(gts, 1); > + ret = -EINVAL; > } else if (gru_retarget_intr(gts)) { > STAT(check_context_retarget_intr); > } > + > + return ret; > } > > > @@ -919,6 +922,7 @@ vm_fault_t gru_fault(struct vm_fault *vmf) > struct gru_thread_state *gts; > unsigned long paddr, vaddr; > unsigned long expires; > + int ret; > > vaddr = vmf->address; > gru_dbg(grudev, "vma %p, vaddr 0x%lx (0x%lx)\n", > @@ -934,7 +938,12 @@ vm_fault_t gru_fault(struct vm_fault *vmf) > mutex_lock(>s->ts_ctxlock); > preempt_disable(); > > - gru_check_context_placement(gts); > + ret = gru_check_context_placement(gts); > + if (ret) { > + mutex_unlock(>s->ts_ctxlock); > + gru_unload_context(gts, 1); > + return ret; > + } > > if (!gts->ts_gru) { > STAT(load_user_context); > diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h > index 5efc869fe59a..f4a5a787685f 100644 > --- a/drivers/misc/sgi-gru/grutables.h > +++ b/drivers/misc/sgi-gru/grutables.h > @@ -632,7 +632,7 @@ extern int gru_user_flush_tlb(unsigned long arg); > extern int gru_user_unload_context(unsigned long arg); > extern int gru_get_exception_detail(unsigned long arg); > extern int gru_set_context_option(unsigned long address); > -extern void gru_check_context_placement(struct gru_thread_state *gts); > +extern int gru_check_context_placement(struct gru_thread_state *gts); > extern int gru_cpu_fault_map_id(void); > extern struct vm_area_struct *gru_find_vma(unsigned long vaddr); > extern void gru_flush_all_tlb(struct gru_state *gru); > -- > 2.25.1 > > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/SubmittingPatches for what needs to be done here to properly describe this. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot