Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp202973imm; Tue, 3 Jul 2018 17:11:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLQSTtTJ7hhLhSxLtS7HLj/+ezzpzM7ZaWr6Oy/DOWsQcbxqpb71sRNB2IxFBDzlOt4ZIxT X-Received: by 2002:a17:902:7782:: with SMTP id o2-v6mr32067170pll.93.1530663111568; Tue, 03 Jul 2018 17:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530663111; cv=none; d=google.com; s=arc-20160816; b=1He5XuyonK6b5zZvsHy2ldBPD+wgd75LK+gZmFzH50apjLDrURTWIqi9pnAmB2ORwO lmmfhnVwEpHZ+zm3K9hzocq0IsQHcGLSpXAphbHKBQnfHCEY+AX/dKbRqswSjQ1F+lPW kTh39IDiLVPfwZ8rTDIvxrhLuqFaIg0w4xYbvVO/WQUfj+OmdGxZNlw4cEqr/sDrxMcv 5jqHH38qNQ80EJ6nNIV3eJfTKkJ6bwth5UjM3boobAvuLCynBgyo7F/d7Qh3hs7a5qGY 6lePsLtgWfUEB7Ax755UcbSdqabe4fcVFZg2xM+537bi4VhHn6XfgVBA/+J0xbQE/DK1 HDIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:cc:cc:references :in-reply-to:subject:cc:cc:date:to:from:arc-authentication-results; bh=jl3+jxOpeJegvvSgm6RpL8BOtVj8OFuj8nJfo++q+h8=; b=MbMDROKiYgH/JOtA1lsD7T4beEs0BS8gOdU7kuiddXaLJADyZr1ziqOjcVwDY1VUVo 8qgbr1YruL/TYixdYia4Y5FYw4YkMj2Axjaluw5KWR7lp/SoLqgWWEjysa5idu3GEwsQ ntmqHXmB5NaNyrUho+NJMaMbg8JHOgeHEJd3zkgQVNDMx7m4Z4F1DwLwjM6snw3xUOMm ds/Uucks3hUg9EEr1AmF6oZQPb0KZwDSIoCmO0BxvGZw38zpLz+Smw79bA0R4LTGpiVj KGBMvGm68xphxOwqRVV9jK2ZGPMQmASHb16/1bDNkpVwsZbfIjKqgzkSa92Hbp4tMwNh hKLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e85-v6si2298319pfl.132.2018.07.03.17.11.36; Tue, 03 Jul 2018 17:11:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753200AbeGDAKy (ORCPT + 99 others); Tue, 3 Jul 2018 20:10:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:57418 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752197AbeGDAKv (ORCPT ); Tue, 3 Jul 2018 20:10:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Header field occurs more than once: "Cc" occurs 4 times Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CB9CCAFC0; Wed, 4 Jul 2018 00:10:49 +0000 (UTC) From: NeilBrown To: Andrew Morton , David Howells Date: Wed, 04 Jul 2018 10:10:39 +1000 Cc: Anthony DeRobertis Cc: linux-cachefs@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH] cachefiles: fix multiple-put race. In-Reply-To: References: <20180222073330.36259-1-carmark.dlut@gmail.com> cc: Lei Xue cc: Vegard Nossum Message-ID: <877emb2740.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable cachefiles_read_waiter() owns a reference to a 'monitor' object and adds the object to a 'to_do' list *before* calling fscache_enqueue_retrieval() on it. The reference is passed to the to_do list, so cachefiles_read_waiter() no longer owns a reference and shouldn't be accessing the monitor. cachefiles_read_copier(), which handles the to_do list, might call fscache_put_retrieval() *before* fscache_enqueue_retrieval() takes its own reference. This can result in fscache_put_retrieval() trying to discard the op twice, which triggers an assertion failure, and can result in freed memory be accessed. The former looks like: FS-Cache: FS-Cache: Assertion failed FS-Cache: 6 =3D=3D 5 is false ------------[ cut here ]------------ kernel BUG at fs/fscache/operation.c:494! A previous patch from Lei Xue moved the fscache_enqueue_retrieval() call inside the spin_locked region. I think it is cleaner to move it before. Reported-by: Lei Xue Reported-by: Vegard Nossum Reported-by: Anthony DeRobertis Signed-off-by: NeilBrown =2D-- hi Andrew, this issue was first mentioned in https://lkml.org/lkml/2018/2/22/82 in February, but David Howells doesn't seem to have responded. Can you take the patch? Thanks, NeilBrown fs/cachefiles/rdwr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index 5082c8a49686..553a71a2c9cb 100644 =2D-- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -56,11 +56,12 @@ static int cachefiles_read_waiter(wait_queue_entry_t *w= ait, unsigned mode, object =3D container_of(monitor->op->op.object, struct cachefiles_object, fscache); =20 + fscache_enqueue_retrieval(monitor->op); + spin_lock(&object->work_lock); list_add_tail(&monitor->op_link, &monitor->op->to_do); spin_unlock(&object->work_lock); =20 =2D fscache_enqueue_retrieval(monitor->op); return 0; } =20 =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAls8EIAACgkQOeye3VZi gbm2BxAAr/wWv/kNxmNXceRJn4DDgS/MegfD6iELaykmQu5MMlg5zkqkZBf8vAvn ONm31Pl3vZ1p6af4Hx74yt/rYyWV2YYV8YqzNlcXLngFN4udth+T1/L4fGJ5qY3j mXoGyfXgFyxR6dhzOPvDmqiIQ9YO1mVnjCzUBe2eDrIGtEYwARkqOWnCcLuo9yIk ps5jdTfT/kJhEBtCNHL29CnhN8lytvrpIGbWPh6pGiUnpxc0YkANjT5AnwVZs/sy lB9ASRaY4q3nApJXIt+ieqTAZP3Qp9liqPkVEOFzxd9FsK15gynJVQAf43DJfdoP 5sl7alwasbmYyQC3NeTbpcqaxs6yeoXJNpsnAVVGZOXebEra21ESlg2/6YRUz767 ggS9sSck61DOvD5ZyUFJcJDlGP5CNteT3tS0BehjFB7gNaBy2W3yVyrDTjruz5BV UBGLYjM356kbgWt1j9jndgQL7SS0yC3szpgOefvz88KWQ4WUzKQT3mv2+WmIs7K1 jU7RXEsZmvKj2VDUxlK1jVeKw+ydTV2LCQF3vuIBbLcquI1/Gv6LRXAUPCxqSyW0 +UsM5zPhpwGMaq6MH+nvh6n6EwN3you1cvvHI0+suPwB+LsnFc8M4gKzvOm0AjUC qC8zGPpW8phaxYi0cHozOjAv6y4W0anQdJPlwyLVQbfP/mPmQ+Q= =KC/0 -----END PGP SIGNATURE----- --=-=-=--