Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp763111pxb; Tue, 12 Apr 2022 12:48:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNFcp0yDVor00lMoKFNfDyACt3vsU6HS+t3sJyJy375KxmXggWQNGSfpIc4lgawOCpEwVi X-Received: by 2002:a17:90a:aa8a:b0:1c9:bfd8:9a90 with SMTP id l10-20020a17090aaa8a00b001c9bfd89a90mr6854097pjq.118.1649792926455; Tue, 12 Apr 2022 12:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649792926; cv=none; d=google.com; s=arc-20160816; b=GSllam8HWCnTxyHl+vnRx5DpLKkbrwnJxlXymxFbKzBtMBf2gTjimofI8nIjXx0DLZ W5ZWbZRGdVozhBrBbYC+RUxQEQtAvTPL4XZzmbDvUnsIgSo5YKAQf9MJdhNhtQxKZq9K qLts3KLU20A67nYQz6eKAAm2Yx7FY/730cKf6d+9TMA2pAlIh24jFR7FKydAZUepkKqh BN79yrV+nUddn7ALtq0/h22AUIzHmm73qYzvlWHksXOxt2/Kyy4YbZt7c7UeFQzYJ+TG L5eg5b3KgE7n+lBqcSTux9Om1Ctzm3nITok+w3ugbBMSb9ITxsdX7BgVaCTM/9LbHKk2 y6gA== 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=cnsXhimyie5ALvB+LjsAXr4bOIi56ZCQ2RpeQ1iKjzQ=; b=W0Cx3ytaQ5QckLjLnD5z1oicMEEp7julJ1PIzoyihJ9l2DzakNmklL5gzxke7EuH97 hScTVlvp74jxfbKT2HnQGBeaTj8nz6smocOroa/sqbw705deKvSrPH3Iqma5PFkLh2OR 9yvDMjNuPCFFAFh59ZFFbyqRhY6zk62qUceV/jGyMq/0IJxXGXEkCxwI0XeiBhQECP7x eBJJJpGFOZea0otAxRS9DvJ1WSTv5vcN+DEENYuGcPOCJJmFsWNhv/0qA+/cf8iiO2z6 jt6hFDoWIXYnkUVWuLTUKx4Wk4pk4CQsZ6IfKPQda/PO+9lA4LMZQ79BXfPr7eaS1oEj BjyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v0I6uaZ3; 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 j184-20020a638bc1000000b0039dafff029fsi48769pge.447.2022.04.12.12.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 12:48:46 -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=v0I6uaZ3; 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 B9ED36581E; Tue, 12 Apr 2022 12:44:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350883AbiDLGvS (ORCPT + 99 others); Tue, 12 Apr 2022 02:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351616AbiDLGpY (ORCPT ); Tue, 12 Apr 2022 02:45:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67DE43B2A3; Mon, 11 Apr 2022 23:38:47 -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 188C5B818C8; Tue, 12 Apr 2022 06:38:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EBC5C385A8; Tue, 12 Apr 2022 06:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649745524; bh=D944uUbc/6izxyPltKm9CFJmV8F0UltJQMAc2SdL3hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v0I6uaZ3qQbNGAu0MMoLx/8y4CFJtQ/+rqoTV34+L3SlSr/zfPex3FMGEI/a+BP/v sWsH59hu3TQCMFbQW49dpWtfIfA4kIHW+sRyB2VXH5QCaNvqqZ0AoOncZO1IVsXTFL gYnFX21VlrjQYJwwOhs6FEd4u6lJyZA126SNiMm4= 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.10 126/171] io_uring: dont touch scm_fp_list after queueing skb Date: Tue, 12 Apr 2022 08:30:17 +0200 Message-Id: <20220412062931.529569593@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062927.870347203@linuxfoundation.org> References: <20220412062927.870347203@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 5959b0359524..3580fa2dabc8 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7346,8 +7346,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