Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3862841pxv; Mon, 28 Jun 2021 15:03:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI3MVfNi5yDTA5swBZCzGLIwGjRWl2TaCNxSGJiYQ5jjTfDelScQdVcVZKMK00iFmmF7BA X-Received: by 2002:a17:906:744:: with SMTP id z4mr26497748ejb.347.1624917779928; Mon, 28 Jun 2021 15:02:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624917779; cv=none; d=google.com; s=arc-20160816; b=AXw1xeJeV1QsTKAsFRXnZMMJg+lNEo5liBV38p5b2x9SDZQcM74RG4OpDIduelwibt Ukc3+PZzqnZjXVqFgzWVkHDsGfMNVOHd/BrLRod132EjKGLZd0BCxWB3T6OOHTfL3n2g YyKmhxORkOKTi7x3RMlvE4ORfvWFBfRXE2iyR6V9jzV3qaUMVBcclloBQ+2J2ajqGUZS c5pjmcZ5bxbs+iclUvgWHpSzDybrHe+wWJRHw9OxVPDG8+HkWbBbc10igJ1YLHwPuRsG RM2NAcsahJMsrDYcXpQ7rW9JbYk7YvnC8EB5T3+BSlhPpWEKplM2CF9p0V2Q+BMlyrZY vW9w== 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=TPgPUQkkMfqFi2oFa7rXdn6tddBxcGbMHfhhXYL21w4=; b=teZb5nC9dhWzZZJiSoaJSiCpv28MbZ2wqlVfutFygbes6M4q8JoTNCMcU+6SBewnPJ +iVskuA95vQbMEmKf3zxtftl/3dWHEnTF/hBjlHfC6cTla5W77ZoVtKoHNrwIRev+8Dl 9dNhOh4mDXzL7mYDCLsI9CQbaVfGnVT1MtmMfP11Q32FjU84SduVMjilTC0z6bbobIX9 cNBIka/n5jh2vKed1A8MK3j+neT2yKMvDPD8YyIqR5YnlGd4rebDSlnEDN+cLHCVe1mV xsywIcSNVbHrHxJXG25whhiwardXGqI66Ai4ewIaWZaou/dcD+02Ji0I2YkVNIUTeI5U mI2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TBsJRa6l; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jx15si1057631ejc.135.2021.06.28.15.02.33; Mon, 28 Jun 2021 15:02:59 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TBsJRa6l; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238602AbhF1PYg (ORCPT + 99 others); Mon, 28 Jun 2021 11:24:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232654AbhF1PAi (ORCPT ); Mon, 28 Jun 2021 11:00:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6406061D74; Mon, 28 Jun 2021 14:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891258; bh=I+GWBZ/4lDqFfHc3Y8W5fLceRDT6D7V3Ua+AYQ2cNYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TBsJRa6l9sTjlojt/rL6VwX8PnzkybuXzhxST3eLbZ3izHNNhuBkD4UfVC9w6uPR0 7Ej2KeP45U9XuvkxXHqNEkTHc7SSPZWtuwBPJOSL8WI6Ka8n69KaFVBczCvmSMtbqU amZivpAnwQebeVUpIeQd3uGPVPR/GLUjtyX/BEDeWzo02ShZSNI2Jg2gn/9/lBcyMR 6iGCJVWl+qLoohOwK4WC28+eh4MrHGbqv2gmdzRqgGKV8s6+gIIvY7UrxGI+aGT8sG bZJbTpiuU9DdYrZVrIxw77ftewmtMFn6uAbeeQARRv2/uw+mrjjmyjCN5xZkD1Ok92 KTuBjFhKAGqqw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Skripkin , syzbot+f303e045423e617d2cad@syzkaller.appspotmail.com, "David S . Miller" , Sasha Levin Subject: [PATCH 4.9 61/71] net: caif: fix memory leak in ldisc_open Date: Mon, 28 Jun 2021 10:39:53 -0400 Message-Id: <20210628144003.34260-62-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628144003.34260-1-sashal@kernel.org> References: <20210628144003.34260-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.274-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.9.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.9.274-rc1 X-KernelTest-Deadline: 2021-06-30T14:39+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 58af3d3d54e87bfc1f936e16c04ade3369d34011 ] Syzbot reported memory leak in tty_init_dev(). The problem was in unputted tty in ldisc_open() static int ldisc_open(struct tty_struct *tty) { ... ser->tty = tty_kref_get(tty); ... result = register_netdevice(dev); if (result) { rtnl_unlock(); free_netdev(dev); return -ENODEV; } ... } Ser pointer is netdev private_data, so after free_netdev() this pointer goes away with unputted tty reference. So, fix it by adding tty_kref_put() before freeing netdev. Reported-and-tested-by: syzbot+f303e045423e617d2cad@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/caif/caif_serial.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c index 32834dad0b83..1243c2e5a86a 100644 --- a/drivers/net/caif/caif_serial.c +++ b/drivers/net/caif/caif_serial.c @@ -362,6 +362,7 @@ static int ldisc_open(struct tty_struct *tty) rtnl_lock(); result = register_netdevice(dev); if (result) { + tty_kref_put(tty); rtnl_unlock(); free_netdev(dev); return -ENODEV; -- 2.30.2