Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp50180lfv; Tue, 12 Apr 2022 16:52:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK19/unV/w6lXjEC5u5W/d0EpybIvtaZTXJkHYzmzBfU59Iki/2x7rMIm/az+vhDHdEu+J X-Received: by 2002:a63:1665:0:b0:39d:17c6:17bf with SMTP id 37-20020a631665000000b0039d17c617bfmr16765683pgw.563.1649807552175; Tue, 12 Apr 2022 16:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649807552; cv=none; d=google.com; s=arc-20160816; b=FpwzDgvZOQx945OIOzFxw43OccYyseq4xQwN8EgNq6smkK3sX58v2VJGe43Jkm8ZUV JhO/FiNS+UxrFWNuMsnXytc+XGreRleFiWX+qhL3jok3JVq8zMRwCqLLEBT9QF+EY4/G WlH5Ar3tq5E7ZnUwVYXoVEl2RFTifBz2zqHV3y0/b98m+r+eL2R15DfZ6Ezkd6xxtLr+ VjxyE/u92VQsOYee3GFCFwb7ksx0gD/CfFQSGnTsLgxjl4MJB3K5ou+XyfACHRx3Aw0M AcBzY42+ONzWpMexEb0zMuYlJcXp+XA/VDQ967f6tV70gpO7tC7JyyBPmpZRBkYz1QA6 e0gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rt1Cv9M7bOhxgGA2blYcoJQcTVdmyQ4813DBDgO2I7E=; b=uw/hFbBtGLswAdTXHLx4BqHTduyK986eElune7KKBVeE9uR4hmLrFqZgtEZBiSd+fb Z7rmMJoyzJAmUKpdyPGSF3QQ+hzpgMlBBP6GthgxVYcY2mRDeqhgZwWl8gefn+Y2EWib XSBlqZkB54mUdlY6Sqzd5guUpw9cb1GSF+M1dvPWLc1zZOXTDC4Q2w66rE7zLuVrsJ6x byRoBroViQ1EKS2idY1ahxBOMQ5ygxJCejLNnzlqUTBTbGDF5koK3Sg18xyjlYHw8RTQ hll0gq5I/6Eh7E71avBcB5XEg9bB8m3g+gcwJ1/e16CdsdQ2Fa0OQrg03J9KnLr9BQu7 ZZNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TUQR0LSf; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l63-20020a638842000000b0039da71704a0si1767040pgd.877.2022.04.12.16.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:52:32 -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=@linuxfoundation.org header.s=korg header.b=TUQR0LSf; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C4011EA5EF; Tue, 12 Apr 2022 14:46:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356394AbiDLHf0 (ORCPT + 99 others); Tue, 12 Apr 2022 03:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347457AbiDLHLz (ORCPT ); Tue, 12 Apr 2022 03:11:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 947794AE0D; Mon, 11 Apr 2022 23:50:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id EC742B818C8; Tue, 12 Apr 2022 06:50:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23A5CC385B4; Tue, 12 Apr 2022 06:50:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649746201; bh=E3sHZwE7Y3egda4sYsmhC+E3OtwsJ2haWtifZ+1d1k8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TUQR0LSfGoWC5ez7JAi2L4RrsxTZm3bypxmtj42bqFoHytbD85IVSGyh5QcZaFLBx qE2xx++Ucalb2WB2l5kFhFzlNF1UY3C3i9/YpMGLhYEtS1XueZnpzefXqjCJfp4Tqf 0a7by7RosJ4LlygoOtwZU1rUiFyX1SY6I0tD3wrI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe , Sasha Levin Subject: [PATCH 5.15 198/277] io_uring: dont touch scm_fp_list after queueing skb Date: Tue, 12 Apr 2022 08:30:01 +0200 Message-Id: <20220412062947.768668204@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062942.022903016@linuxfoundation.org> References: <20220412062942.022903016@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 From: Pavel Begunkov [ Upstream commit a07211e3001435fe8591b992464cd8d5e3c98c5a ] It's safer to not touch scm_fp_list after we queued an skb to which it was assigned, there might be races lurking if we screw subtle sync guarantees on the io_uring side. Fixes: 6b06314c47e14 ("io_uring: add file set registration") Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 21823d1e91de..2faa558778ba 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8126,8 +8126,12 @@ static int __io_sqe_files_scm(struct io_ring_ctx *ctx, int nr, int offset) refcount_add(skb->truesize, &sk->sk_wmem_alloc); skb_queue_head(&sk->sk_receive_queue, skb); - for (i = 0; i < nr_files; i++) - fput(fpl->fp[i]); + for (i = 0; i < nr; i++) { + struct file *file = io_file_from_index(ctx, i + offset); + + if (file) + fput(file); + } } else { kfree_skb(skb); free_uid(fpl->user); -- 2.35.1