Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2920311pxb; Tue, 24 Aug 2021 10:37:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0S7F9A8a429SELsCIBhlGUvTSRBg9dV0h7uDcYmEv2W07fsSSnYw3yqpbdxNpUfccACRi X-Received: by 2002:a5e:9e44:: with SMTP id j4mr31819692ioq.171.1629826642058; Tue, 24 Aug 2021 10:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826642; cv=none; d=google.com; s=arc-20160816; b=El+MfAiY427JUS1QaigULNANSbY+WTt9yunXjBFgxQOpN+b6KIWShPyQ0Xoe+xYdHa 3N89ae21W9naOpI1a6KzHABRbwB4ryC4Ea7Ugl9lFz10J8wAMoqN3EKgkjqAzehSzWSG F6m25x/ulcOdF6UTeLs8PQJotvTjTMv2bl1jp5lPExRlThgBQYURXzj94oTNxJRbmG4L gm3IHTtZLrpkux/A6ExjRZx68Nzyl4g245TiGaBrWpmFoxu1bv3wGDZYb+4Yx4g/n0vw 7uJQVPUf7+oPnhZW+oyR/KhOpUaDKZYIrLFemWhp7pfKC1JqKaYoiSZUpmWWbsaX1ZOY xA7Q== 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=SbuBxei+ndWBbcSlAoo2Lo0BOmlthOcH/55VISlYX6s=; b=LCvQdFnqqJx30nsysLqDdP6hna/giJuSK7qPJiZ58OSp8caNEZaPcoG0ZdPy9fumFL Czq9a1zzDaAK9v+UNMbXlchaXuOQsw3U0MIaGKBx7x62qqLecknBC65lHcLHpaPuvXxM 5HKKfXwNIWbqsyy6y+nw6WcEZMJVohv1JMKqoxY0/04EQHRrUu0nrno9JFW0Khr5S03T 3nfG2V8AGwVOsI/ymo37Bo6DzoFDaO0++rcxj8OEnoH2RTRcDoOL0/2K3XA7lQsZicVf f9Crm2AKEKFsy4cGhSZnNX7MLqbCbPlkdLAf4gTGdXKbKm1IFSnJvL/B/vb6a8NRACnC XUoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EVXBuueC; 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 y4si21953123jas.59.2021.08.24.10.37.10; Tue, 24 Aug 2021 10:37:22 -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=EVXBuueC; 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 S241712AbhHXRgk (ORCPT + 99 others); Tue, 24 Aug 2021 13:36:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:39252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241631AbhHXRdK (ORCPT ); Tue, 24 Aug 2021 13:33:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3BF4F615E5; Tue, 24 Aug 2021 17:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824781; bh=z9PNdo8n76f8x7IR+LSr4oEuoLqnAbavaFgdFyToI7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EVXBuueClkCXXNfwt6I0hfgKYkvlnhQTl+u7FUEPCCCcX9egh2R2S8fkDSa3RRDA1 MIvdoBCYgxYnTJ0Y5+XPsPclo36qW6jdZk8WUNKvIfX4Qe1ESNMtjUDDcmnxGIpZRo uaEjo4+S64BdOXyUv3TGhbVrl6NeboOUT2ohTNf5PRQHJ4/r70sSdXpbjGN2jJu4H7 JfoyVzEQUnc+Xq1VWQNyWCM2rYvtXdHqbXSCeu0aANjXSvWzVidX17Hd8Jvc78a9Dx RBZgVKLtUvoguSEwlonoEJJTeWS2K+WBAkrRlqy3EOXtBlGhZYPQ15w2OuUGLyjhsv YPB7ReIiGnPyw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Pali=20Roh=C3=A1r?= , "David S . Miller" , Sasha Levin Subject: [PATCH 4.9 05/43] ppp: Fix generating ifname when empty IFLA_IFNAME is specified Date: Tue, 24 Aug 2021 13:05:36 -0400 Message-Id: <20210824170614.710813-6-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170614.710813-1-sashal@kernel.org> References: <20210824170614.710813-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.281-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.281-rc1 X-KernelTest-Deadline: 2021-08-26T17:06+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: Pali Rohár [ Upstream commit 2459dcb96bcba94c08d6861f8a050185ff301672 ] IFLA_IFNAME is nul-term string which means that IFLA_IFNAME buffer can be larger than length of string which contains. Function __rtnl_newlink() generates new own ifname if either IFLA_IFNAME was not specified at all or userspace passed empty nul-term string. It is expected that if userspace does not specify ifname for new ppp netdev then kernel generates one in format "ppp" where id matches to the ppp unit id which can be later obtained by PPPIOCGUNIT ioctl. And it works in this way if IFLA_IFNAME is not specified at all. But it does not work when IFLA_IFNAME is specified with empty string. So fix this logic also for empty IFLA_IFNAME in ppp_nl_newlink() function and correctly generates ifname based on ppp unit identifier if userspace did not provided preferred ifname. Without this patch when IFLA_IFNAME was specified with empty string then kernel created a new ppp interface in format "ppp" but id did not match ppp unit id returned by PPPIOCGUNIT ioctl. In this case id was some number generated by __rtnl_newlink() function. Signed-off-by: Pali Rohár Fixes: bb8082f69138 ("ppp: build ifname using unit identifier for rtnl based devices") Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ppp/ppp_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 5ba472691546..0a29844676f9 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1136,7 +1136,7 @@ static int ppp_nl_newlink(struct net *src_net, struct net_device *dev, * the PPP unit identifer as suffix (i.e. ppp). This allows * userspace to infer the device name using to the PPPIOCGUNIT ioctl. */ - if (!tb[IFLA_IFNAME]) + if (!tb[IFLA_IFNAME] || !nla_len(tb[IFLA_IFNAME]) || !*(char *)nla_data(tb[IFLA_IFNAME])) conf.ifname_is_set = false; err = ppp_dev_configure(src_net, dev, &conf); -- 2.30.2