Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3799539pxv; Mon, 28 Jun 2021 13:12:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWh9XixM2oMIi1AEtq7aSC8Xbk9JcTu72R9lkppiNuZ+h6i4JQ2+st9vrdTurmcvRar5Di X-Received: by 2002:a5e:8208:: with SMTP id l8mr928293iom.197.1624911134773; Mon, 28 Jun 2021 13:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624911134; cv=none; d=google.com; s=arc-20160816; b=ocubiQK/iYp/SME2dk9bGZnFLHQqpBWo2IyywX60X41emammstlZpwKJNe0ORPuqZt OzqPKuqsGlXJMg5FmY2h/lV4IuS091/yhc3geH0EOtF/G2OeqyRDWDm8+aahM6XXdKcS 1jPQSnUywvNcavSDmMEoMcA1/mJT8orUKpkhuGVgPdyUrSYDRWZQnELQYJsh3nSrDXvO pWaHydVqAsnK8UpMhv4OXxpsSjjYbHRpqFij8i6sJm6BLKFx3aLIKJ03B1R7aXgYuV0W ZqdARfUdTz6Vbj6aTJ6bSODi4Uzk0OR9LpQcN2tL/jJ4QUHRGVlRSL6HgkouBBT0XIQ6 3FpQ== 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=u/s2SVMxbZXyVOKKjnD8FugFHth2PvEUnBrwwE6h6Yk=; b=O9RtNoEP8SdYqifo028fHbVNjZQXnEDedsuZdO8EpWQiX8q89rJGLojQYB3E3XR0Hl nLZagbjFPBfGVQ2au3q+xfgy9VLTRWVfDmKXI4gap7/p7YUPu65t+5HtPEN89cEuQtif Xak1QsWKpYv/EYKZCrfN1KzVko43MY3Zs7mUn0TS3hlQe/lgPhNrJ/gfa99oFep5uJFB CNaDU5w/sUtfwfQ04kqTTJ/gRyxD/z7vNMwd2rHPq4GiTCgHmnpCCoxYCga6zmhR6Pji 2zqG6jN/1tilAutTrUcMMh6AZt53r28bL6BwtfSPufq/zs2qvOLmHZgNgmEcQGDuuB58 yA0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nI7ZxeTp; 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 n13si14051987ilt.111.2021.06.28.13.12.01; Mon, 28 Jun 2021 13:12:14 -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=nI7ZxeTp; 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 S234427AbhF1PDr (ORCPT + 99 others); Mon, 28 Jun 2021 11:03:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:53670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236101AbhF1OqQ (ORCPT ); Mon, 28 Jun 2021 10:46:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0458661D12; Mon, 28 Jun 2021 14:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890871; bh=el34oshqV5/fwop7i2A8DNlQAMiado0YSzkogBPgeVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nI7ZxeTpJFbuoJQkzzb/EVfKZwbzDSt7P+elsVMuXRDpHAQyJ8G6rS+Tu5yu0HW4a 2SmOVRZv1KoMaNHlTihRebLy7xfv4FIp0QtWBRkqcc1NVcbBdWx4v+zOqD47DwtgqY eyQ8N93FHIAOfRLyKfRFlRHjeMPr28qeYr2gvt5QWs/MM7uCTyUJ5PEkoq08k0VgV+ S3bAAVuNh/7jAcog0uGXzzwlCZqmNc20cbFW7eXc8VA/vQI3GoVFPDqWghRyUecyC6 dRvqTuA/akEMDhlbG+4/nRIkvim4jKDeUjV0zgjjxTXlm/Dm1kRI0zzK7eMTc/CT+D hybNtM1Ta/Dlg== 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.19 096/109] net: caif: fix memory leak in ldisc_open Date: Mon, 28 Jun 2021 10:32:52 -0400 Message-Id: <20210628143305.32978-97-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143305.32978-1-sashal@kernel.org> References: <20210628143305.32978-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.196-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.196-rc1 X-KernelTest-Deadline: 2021-06-30T14:32+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 94d5ce9419ca..81ec17b9c49c 100644 --- a/drivers/net/caif/caif_serial.c +++ b/drivers/net/caif/caif_serial.c @@ -360,6 +360,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