Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2619748pxb; Sun, 17 Oct 2021 20:42:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwB45ni/rSdBZ0YzzO77XLmVmpTJqtuERuXlIZF9guiEbuyR2RV9ZUfXeDhL4tBNDxp0Tno X-Received: by 2002:a63:7e05:: with SMTP id z5mr21347534pgc.354.1634528576384; Sun, 17 Oct 2021 20:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528576; cv=none; d=google.com; s=arc-20160816; b=JNVwDnl8PLZcbCfeKwuavrwRrdDhsqn+nCQo+w0Gca70S0D92PDZZAi7kOO4y4m/uC q3Gp2fGedLpM6WqWn9NIGzj6q6Y5YBykeYhTt3zKXfUyRMctOkjlLrk0Lm/49PE3VA3e nFMKWqnD/ZvUdbY6CCXki4fou1ljsGWdoHVfT4ii36wXX+6U64Md/aryumCwy5WR2f8f mki7nb4DkAi/g7o34qdo8xsHtG+2ELxUgO5K8PpgPR+dTLcEVhZ0db/718fELCyagVI7 lkw1VIwlPf5+gl6fhsdfrnrF7cYjEubvm+SJSYuw4lg1+p92oUwzVHME+5kJnJQcjA3f CUug== 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; bh=qMnByeQTEIJlsqFUdpkxkIhRmenpZ7ZrPlCGf3/vu2g=; b=y8lgISGjDnB+9HWVgCFnT3GVW/TCuMVTTQRaoXtkgRs9suBHc+cSyHIdVQ6i9g4ume r3mHixaM0wPsJbHs0XUP0traSPw40zs8fMm0YcH2gLTfOu3sLjfmw+Ja2LMisOocvAZ3 1HYWoMnU+uFabftfzu9R4Pvb25eIdM+rGVlGlwTvgVLo10FBI4IXhEBDpURI4SBVJ1Qx ZjkRiecuveo24D/RmjFvwfiwE2E0VzqJxFho0i+MrG75t73zDo+5Ih7V6KXKZhxMM3G2 KKLVD2qq/kd9ZBamvFWmm8zpJqaXXs+HkUDFHW6DUJBPelPDFo1NMCPDWCIREcx10U5u NSAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si19961899pgv.175.2021.10.17.20.42.44; Sun, 17 Oct 2021 20:42:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245356AbhJQKuc (ORCPT + 98 others); Sun, 17 Oct 2021 06:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242155AbhJQKua (ORCPT ); Sun, 17 Oct 2021 06:50:30 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B19F3C061765 for ; Sun, 17 Oct 2021 03:48:20 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mc3i7-0002kV-U1; Sun, 17 Oct 2021 12:48:11 +0200 Received: from pengutronix.de (unknown [195.138.59.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id AFA186958B6; Sun, 17 Oct 2021 10:44:00 +0000 (UTC) Date: Sun, 17 Oct 2021 12:43:29 +0200 From: Marc Kleine-Budde To: Ziyang Xuan Cc: robin@protonic.nl, linux@rempel-privat.de, socketcan@hartkopp.net, davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] can: j1939: fix UAF for rx_kref of j1939_priv Message-ID: <20211017104329.ccz3r5lsadqpbuj5@pengutronix.de> References: <20210926104757.2021540-1-william.xuanziyang@huawei.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="lfm2fzo7ig3sk3dm" Content-Disposition: inline In-Reply-To: <20210926104757.2021540-1-william.xuanziyang@huawei.com> X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --lfm2fzo7ig3sk3dm Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 26.09.2021 18:47:57, Ziyang Xuan wrote: > It will trigger UAF for rx_kref of j1939_priv as following. >=20 > cpu0 cpu1 > j1939_sk_bind(socket0, ndev0, ...) > j1939_netdev_start > j1939_sk_bind(socket1, ndev0, ...) > j1939_netdev_start > j1939_priv_set > j1939_priv_get_by_ndev_locked > j1939_jsk_add > ..... > j1939_netdev_stop > kref_put_lock(&priv->rx_kref, ...) > kref_get(&priv->rx_kref, ...) > REFCOUNT_WARN("addition on 0;...") >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > refcount_t: addition on 0; use-after-free. > WARNING: CPU: 1 PID: 20874 at lib/refcount.c:25 refcount_warn_saturate+0x= 169/0x1e0 > RIP: 0010:refcount_warn_saturate+0x169/0x1e0 > Call Trace: > j1939_netdev_start+0x68b/0x920 > j1939_sk_bind+0x426/0xeb0 > ? security_socket_bind+0x83/0xb0 >=20 > The rx_kref's kref_get() and kref_put() should use j1939_netdev_lock to > protect. >=20 > Fixes: 9d71dd0c70099 ("can: add support of SAE J1939 protocol") > Reported-by: syzbot+85d9878b19c94f9019ad@syzkaller.appspotmail.com > Signed-off-by: Ziyang Xuan Added to linux-can/testing, added stable on Cc. Thanks, Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --lfm2fzo7ig3sk3dm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEK3kIWJt9yTYMP3ehqclaivrt76kFAmFr/k8ACgkQqclaivrt 76n81Af+NxBLZqG3wWfCjpl7IxccdICWAetFxDreGHh2/XjF61A99AZ0cTFUA+88 Ygo2PxOaIUDcRE6Ffb+d6HOeDdHZYCKmHNuB7UnUVsIQNoGVV09hRd9gHzTe0SmW IWZTml85rCHRu4mIlvIVfINn21umaPPhqlsggYp4cxB2/uyrvLmC1j0Rh00IGx/1 FgNGSIJW1xlacOXtikg8OoPu1mn/8iAYuz69AVWppchPRJ86hqByc6eYRKirmqcc S0r7Zccb2gZ8cNs5MNGyram8MCB6Jw5+m87rcCxXdJiecqDQra1987MaTEEF7y// Kcm2E4tnvCZNT7gW8/fvfs8t1Pkenw== =qnl1 -----END PGP SIGNATURE----- --lfm2fzo7ig3sk3dm--