Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp723297pxu; Wed, 2 Dec 2020 01:27:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzS8eaX5mtoHQ2DaPpbDi/XqB9uNrNo459LnNtd4yCgwtX5ZuJM9wW7QKVl5UMAPuEiBZxx X-Received: by 2002:a17:906:2a0a:: with SMTP id j10mr1406674eje.307.1606901267049; Wed, 02 Dec 2020 01:27:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606901267; cv=none; d=google.com; s=arc-20160816; b=LC9uDOy7ldQvLujksVqPYjT/iKY+yf3B/y0h12Oxb4De4pHthPvRAyo+EWuLJnN01A Sj50wE31ZOKwTl5LVJtGYRD61uHes8ZtahJFq+5wOqDxS4GzrFO7CX7ULDzfP81/Z5q5 MxWO8qbPETKtc9GOAeNUuycvsiF45/CTFzVRNiXLjYGNMUKltCoVZ0CinEdACVaxQ0QK W4hcWthmL/ekln8wY1YG6l9lMYZSYwQ+//bCo8hjY74KIytLmn8hGdN8R3FTxAjMEEpM DWwV4xYBMqd3lYQUs1X2l6r6C/lAiyi9ohdGMXLoKUqJoPOySpdfkEkCmmnn1rkXU4P/ A4KQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Sy381wm44Taj7NbPSG7JcujeYoy3WsPyZ0mkLGSOBXY=; b=MDBNBJAEGsYL/KW+W8zDvEG+qSeaOoL9WkgCwtdLGb3otbsomXMrDWFrUKuv9pEUog l1ucUpzcU5ul1DFPfmlhGklm3t7QRtRrQymIm09FMlD3Z4gwKgI32REHsqQO1vJPqnAm oHoRyxxQqiTdsXCoCrMNQcVLjc88gLcfJEQd4ispdlnCa3XlN8/D+A4V4tIQ3RuI7RfJ k1NoQC9n8DWhWlQZOvAB6MtIuqsuGsdfEvfGUYGLbXqqo+LGsfFwj2oCQ/bd0qLf3jBc wAAAp5JdmKpeb+12trSt1sb24r6OrvHMugCgx/V6fUBh5DZXdU7K3wdzogyZKVosmabg rpOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nldGpVXk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg4si686692edb.104.2020.12.02.01.27.23; Wed, 02 Dec 2020 01:27:47 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nldGpVXk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388193AbgLBJXi (ORCPT + 99 others); Wed, 2 Dec 2020 04:23:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388180AbgLBJXe (ORCPT ); Wed, 2 Dec 2020 04:23:34 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABCE1C0613CF; Wed, 2 Dec 2020 01:22:48 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id h21so5813826wmb.2; Wed, 02 Dec 2020 01:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sy381wm44Taj7NbPSG7JcujeYoy3WsPyZ0mkLGSOBXY=; b=nldGpVXkmPnJXqgQOox5WtCy9X5FZ3a786yRS1bN3hDVziW4evh6eXGlxbKYVRJJC3 f79Sv24H5qBZXDKwDnmEDHh2Oi9TyV4+3yPpGnz3LS1pbyMbvJVHxIY7sThr8eCoJjhn NmoT/qFz8yEJ6UXdTjPBB3JBessscnKGlKmwnqqjhnOqEephWeNRRmzqnupiSBjnVMzl QdWEHHDr3gmh87iXIgqQ5pjh259m/XH38lIb3zOUQk/2vgC2ljjt4wDBS7rLTuPFzLst qh98x4buDsVP7mmm5pcmhwoCetABUhhp8fQ5SQ+TFCv0Q8Q9QiDj2wsz9piUHAgob40B ynRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sy381wm44Taj7NbPSG7JcujeYoy3WsPyZ0mkLGSOBXY=; b=n1C2k+4m0MhWkiZwEnVFwE7CQU4tr8ptSY6nVW78J+5lkCM6NN/PZ6LCD3h7YqGqDc t2T3kX9qcwujOUykly9YuAloO842Su1SbX4GsJStAiURjLUOvvLmmmbSUBo8zLnZHMQm LZolg95k7Rg+AUNCVwK4mDWHUPqm9VtAplUMJ8GFdOLlnspnhy4o9CALEYAofdVEi7mT eDZCUo+goInuPyhD/c19dh+n9R37QZNeNnSDc9LE4Okf2GsoxQU5j0LCBN6C1lOJAmjX DDaMlHohLa/q9o4MiFXyi98FALSyBnGNL2JjBJplKSban5kly/cg/YN33v8S+m7nVEVr zYpA== X-Gm-Message-State: AOAM5329e5qSEH5lgiPC7ehTu86KS9VwxkaUFeZcDUuBEtMgGLFF6qmB gJhgeJPG25T/ibYx7T0nihgj5UgqAc1sAQ== X-Received: by 2002:a1c:2b03:: with SMTP id r3mr2097953wmr.184.1606900966987; Wed, 02 Dec 2020 01:22:46 -0800 (PST) Received: from andrea.corp.microsoft.com (host-95-239-64-30.retail.telecomitalia.it. [95.239.64.30]) by smtp.gmail.com with ESMTPSA id e27sm1535936wrc.9.2020.12.02.01.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 01:22:46 -0800 (PST) From: "Andrea Parri (Microsoft)" To: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Michael Kelley , Juan Vazquez , Saruhan Karademir , "Andrea Parri (Microsoft)" Subject: [PATCH v2 5/7] Drivers: hv: vmbus: Avoid use-after-free in vmbus_onoffer_rescind() Date: Wed, 2 Dec 2020 10:22:12 +0100 Message-Id: <20201202092214.13520-6-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201202092214.13520-1-parri.andrea@gmail.com> References: <20201202092214.13520-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When channel->device_obj is non-NULL, vmbus_onoffer_rescind() could invoke put_device(), that will eventually release the device and free the channel object (cf. vmbus_device_release()). However, a pointer to the object is dereferenced again later to load the primary_channel. The use-after-free can be avoided by noticing that this load/check is redundant if device_obj is non-NULL: primary_channel must be NULL if device_obj is non-NULL, cf. vmbus_add_channel_work(). Fixes: 54a66265d6754b ("Drivers: hv: vmbus: Fix rescind handling") Reported-by: Juan Vazquez Signed-off-by: Andrea Parri (Microsoft) --- Changes since v1: - Fix typo in commit message - Add Fixes: tag drivers/hv/channel_mgmt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 5bc5eef5da159..4072fd1f22146 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -1116,8 +1116,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) vmbus_device_unregister(channel->device_obj); put_device(dev); } - } - if (channel->primary_channel != NULL) { + } else if (channel->primary_channel != NULL) { /* * Sub-channel is being rescinded. Following is the channel * close sequence when initiated from the driveri (refer to -- 2.25.1