Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp893036pxp; Wed, 16 Mar 2022 20:25:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1xFshDh2BVwgBQgs0iJd2mq4g+SdapZ0+9/aKQrDywQw+bx+rB8BM6l5WUjGrtF8n21Ye X-Received: by 2002:a17:902:ea0e:b0:152:7cf:1b8a with SMTP id s14-20020a170902ea0e00b0015207cf1b8amr3051112plg.4.1647487508704; Wed, 16 Mar 2022 20:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647487508; cv=none; d=google.com; s=arc-20160816; b=hlBIFNL4ic4Q2rlOakzxunMqsWWFmB+mRwf6LfqJhNfvfchmWf4IXpRAeFW0UCCGR4 ExYMM60/m+FwxkwGrdHBIXAGJ8vwkkWhyL0HmW5l5oqGm+peR/WAlGdL6+ZYGJyEUCOi DPZMRRmGhRoDdTSrakT2Uy0rWlNW0fhI1HS8dYcOZiKTZLj4JEH9qnxaaDPtQVnX5HfH H/h7YT8tV1SSwolCiZj/ds7jGRTcmv3KXCkZcfk8jcjNjIz56LJKDa57rh/r80PVctM/ rNkciau8m1m1mKk9OP3RBu1Rq+CCaMU8gJ3nJCM1+UpWnDK9kcuNEhRLZsQDLoAze5n6 wtmg== 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=FzEv7w803jbJYcBpgfAvyNgAVHQGwPwlwyrtbStl4H0=; b=wEE8zq3qkMaitxBYIdmJTxlRdXZRtdWU20kfolU5kIfLsE/3TtpiaMKEPA/eXvlCDY b4VZUQZfZw3dx4bBAJsZmYocO1p14r7sTZ3nenUfO7kemQRHRNwu9y6YXeN+sfVGx8ux SBsqLllt5Ia5z0qawB/r6DviXzhjf25cnN97Iir2lY7WxbswY0VZsWiYOcqgN78FYdDJ +aCs+V4McPyT/xrogG/urpUsIf0ffGD5GKeQAok+K86++wrITeho+chTJsIzDdGR+SsK WZC4UKE4wJNH+9/kg8Pwy8aaxIw+yPVAW3y3qHKaYeyCFF5nQeUUlhDs7Aos+WgvXXol zgJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MYfGh1aN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id q192-20020a632ac9000000b003816043ee79si851983pgq.110.2022.03.16.20.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:25:08 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MYfGh1aN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 46B4F2E09A; Wed, 16 Mar 2022 20:24:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240697AbiCNMG6 (ORCPT + 99 others); Mon, 14 Mar 2022 08:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240621AbiCNMGG (ORCPT ); Mon, 14 Mar 2022 08:06:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB88EBC2F; Mon, 14 Mar 2022 05:02:55 -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 3074961251; Mon, 14 Mar 2022 12:02:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23622C340E9; Mon, 14 Mar 2022 12:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259374; bh=qrjcQzJJwJt0h45ZjSQPyEjka1WJolCH3qzCphW+dps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MYfGh1aNkj1abHawqXcsfab6tFGrniPBAXgCHRp7UjxbcSymYRp5PiteLgFE2V1mw 36IhSJYFAAXpdK27n+hq4ZzeY6Bdxl9iMgsSCPFNBECaWHl13rR8aOrBANW87IN8cN mVV1Zq7ZAsV0NWV8ZiT/c6fyj9T/yOCVkogpxqCg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , David Howells , Linus Torvalds Subject: [PATCH 5.10 64/71] watch_queue: Fix lack of barrier/sync/lock between post and read Date: Mon, 14 Mar 2022 12:53:57 +0100 Message-Id: <20220314112739.730907012@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112737.929694832@linuxfoundation.org> References: <20220314112737.929694832@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=-3.5 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=unavailable 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: David Howells commit 2ed147f015af2b48f41c6f0b6746aa9ea85c19f3 upstream. There's nothing to synchronise post_one_notification() versus pipe_read(). Whilst posting is done under pipe->rd_wait.lock, the reader only takes pipe->mutex which cannot bar notification posting as that may need to be made from contexts that cannot sleep. Fix this by setting pipe->head with a barrier in post_one_notification() and reading pipe->head with a barrier in pipe_read(). If that's not sufficient, the rd_wait.lock will need to be taken, possibly in a ->confirm() op so that it only applies to notifications. The lock would, however, have to be dropped before copy_page_to_iter() is invoked. Fixes: c73be61cede5 ("pipe: Add general notification queue support") Reported-by: Jann Horn Signed-off-by: David Howells Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/pipe.c | 3 ++- kernel/watch_queue.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) --- a/fs/pipe.c +++ b/fs/pipe.c @@ -252,7 +252,8 @@ pipe_read(struct kiocb *iocb, struct iov */ was_full = pipe_full(pipe->head, pipe->tail, pipe->max_usage); for (;;) { - unsigned int head = pipe->head; + /* Read ->head with a barrier vs post_one_notification() */ + unsigned int head = smp_load_acquire(&pipe->head); unsigned int tail = pipe->tail; unsigned int mask = pipe->ring_size - 1; --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -113,7 +113,7 @@ static bool post_one_notification(struct buf->offset = offset; buf->len = len; buf->flags = PIPE_BUF_FLAG_WHOLE; - pipe->head = head + 1; + smp_store_release(&pipe->head, head + 1); /* vs pipe_read() */ if (!test_and_clear_bit(note, wqueue->notes_bitmap)) { spin_unlock_irq(&pipe->rd_wait.lock);