From nobody Tue Jul 04 14:00:11 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QwPZ40g0Cz4l6Zn; Tue, 4 Jul 2023 14:00:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QwPZ36gKLz3D0R; Tue, 4 Jul 2023 14:00:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688479211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iEnj+oULCeJVqtrdImFyp4HvFcvMUkzszaov7FvAQ80=; b=Lcq3WNBAPOotcTzUf0fLHpCZ5mCjNgqDOLTumljH/6Xi9LkfNDnvWZwYG0wLQirXntyxvC qxqvFXhLKtdUx05HGysXYYmPBuOkBL6Uln88Ek4mAOGTKd/8OpAxzTJwjIPEjT342ukTy0 4mVy80v4eIKwfq2H3WQjVk+CPworjLqFF+iUFSPpjVmH+xrbAK4PT5bmoz+eBoPmuAX/JR Fk7fjxw8BVevRv4ZJVIiuTzyHdbSdbNkyN+HrgE+gywNcPLQ63C0fHBkd5txreDxLAOq1j xcWibRUDklT7ftyxmIqPxFxYon3x0MQ2ALLpJZcZzCEGvrjQ73CnF15kL7QE2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688479211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iEnj+oULCeJVqtrdImFyp4HvFcvMUkzszaov7FvAQ80=; b=WbygcigWAO8K9TCfh8LDDdLWLb8rYNXq1yOqWGOy6tUOA2EoZcqt3ySF57lLLpBzHGsq3z Z/M5ZnYY/zx/bcqzttfd0PCusnwq25ywTQf5EHpgLMLddplDIvxgBU859jSzDZFUGgsWtd uOkzfXttF7abolvcPZhmeN+PeOMw8nUtzNy3UHi/rb3zx2SZSSuOnx6yNORl4GKyS1Fd7w 6AOd0NxkiBOx9nchS+X91UZX6gPErPNJLNgiHwpB8D553+egQ6nPkOontbu2WVYcCO584m 4mEoqG0bU7hivfdCJkpnJBggHm1QKgAfYhiEX8L7f3VYVu/zTfo94v61d+MV9g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688479211; a=rsa-sha256; cv=none; b=whEF5kJHo7ujDcqG5Ii3pfC7vq9JSs0SIOAJFE0cN6REeTqHNvYTREhqxdGYCGQbsbe+5h v3+c/y/pwWobzcm00rv6e26zWeA/fVL6aBIKLw6zViXbGnwvZVO2v9XBzF7ZvJLMvl0073 koOKIgo7TXj27L2EpSNrZ1C16jEGblnBYYp6wAOyo/TwD4AAtXSqKIcVAeueyMzKQgn6bp ZRievivr5e4wLZLaYQ+gB14uX16aGloUhvNQ4OBUV8fM+20jmhMtexItmHLoWc0xzSdyaj 6NGnX0WySO4Slr28M2LUlOy46JkLFxnLA30pFLPCpePo0wQUoYG3rO2xeYrXnQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QwPZ3576zzZN8; Tue, 4 Jul 2023 14:00:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 364E0Bon072105; Tue, 4 Jul 2023 14:00:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 364E0BBJ072097; Tue, 4 Jul 2023 14:00:11 GMT (envelope-from git) Date: Tue, 4 Jul 2023 14:00:11 GMT Message-Id: <202307041400.364E0BBJ072097@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Marcin Wojtas Subject: git: c59a5fbd8a2e - main - ena: Fix driver unload crash List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c59a5fbd8a2ef68ed0842cbb1df4450edd654129 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=c59a5fbd8a2ef68ed0842cbb1df4450edd654129 commit c59a5fbd8a2ef68ed0842cbb1df4450edd654129 Author: Arthur Kiyanovski AuthorDate: 2023-05-21 12:31:54 +0000 Commit: Marcin Wojtas CommitDate: 2023-07-04 13:57:15 +0000 ena: Fix driver unload crash When ena_detach is called, we first call ether_ifdetach(), which destroys internal addresses of ifp. One such address is ifp->if_addr->ifa_addr. Then during ena_destroy_device(), if_link_state_change() is called, eventually trying to access ifp->if_addr->ifa_addr->sa_family. This causes an access to garbage memory and crashes the kernel. Ticket [1] was opened to the FreeBSD community to add null check in the code of if_link_state_change(). A fix was submitted in commit [2], however it was noted that it is our driver's responsibilty to not call if_link_state_change() after calling ether_ifdetach(). This commit makes sure if_link_state_change() is not called after ether_ifdetach(). [1]: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=270813 [2]: https://reviews.freebsd.org/D39614 Fixes: 32f63fa7f975 ("Split ENA reset routine into restore and destroy stages") MFC after: 2 weeks Sponsored by: Amazon, Inc. --- sys/dev/ena/ena.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c index a62b99d5ee1b..8429dcd3390f 100644 --- a/sys/dev/ena/ena.c +++ b/sys/dev/ena/ena.c @@ -3291,7 +3291,8 @@ ena_destroy_device(struct ena_adapter *adapter, bool graceful) if (!ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter)) return; - if_link_state_change(ifp, LINK_STATE_DOWN); + if (!graceful) + if_link_state_change(ifp, LINK_STATE_DOWN); ENA_TIMER_DRAIN(adapter);