Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4809857yba; Tue, 30 Apr 2019 04:53:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzi8InO1M1vkukmGJ3iiU4gAdrurfPCZTjyIjJdTQBoMl6XVmm/S5syi9p6LNN0U5obCe+c X-Received: by 2002:a63:cc47:: with SMTP id q7mr39525655pgi.171.1556625188100; Tue, 30 Apr 2019 04:53:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556625188; cv=none; d=google.com; s=arc-20160816; b=yx2UPXz85nR8t5SLuRPfwPCKMEc9g/NTEYyfESOIl9CLzLtsMui4WTFyusdFo9KJ4P 0Pqyr0doX+RI0klnxDupSvvBwNXaoD3oJZZGugOf5UUilgzVr0RQg+VxM0ptcL7oG8Vb ILbS11i893KEuEUINsMThY6AlMRfvYghv6EGa8zo2J9PJaLivM+5BrqIU1eiQ2d7oiQX wPNof4vblrChUpYVVIuCOe2cyOK7/wYcVoTrxY12R36DHUaA8nYExfcS/zA0FM/UZ6GP mybSx6+h25PQ3tESaCk/RZ4kkKvArkjDPar7+3yqh4VfI/BPS17MvUsw/57rRcOs2iZv oJPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jv9T9yqn5X3ds5dI7bhINeBZy0wapbqKqdusVGKKbgg=; b=U8GcxwUvD9jqigH/ICQsrZNOZsn4S38U7rwB7h3FeWRez4EYzTEkooHmk86V6wzGw6 6r85uoz7O3TM9vYyPI48NeTNxzJY7duwMgBZSr+Y3mD6Yine8CGMHMm5PU63rUarCe+R OT51htr01RwP4UgnYPplMN0v0RTkTNNfynuH/0TwSYhbEgqCve50mYq4Xr33rbFqwidI 8PyYaoKUJn1sZUHO3le1jcXHjsi+BPqADMU8VfBjuCjaYCT7oihThOhJF8S/s5YK0fsG Vv2HhC3ttD96fQIgau0CfB7R+lZtTGCpLOm6cvU5B+mh3FhEicEecwe1l+dU+NZFgQfV DchA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c4Rj94x8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si23450534pgb.401.2019.04.30.04.52.52; Tue, 30 Apr 2019 04:53:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c4Rj94x8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731391AbfD3LvZ (ORCPT + 99 others); Tue, 30 Apr 2019 07:51:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:39088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731377AbfD3LvX (ORCPT ); Tue, 30 Apr 2019 07:51:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DFD0021670; Tue, 30 Apr 2019 11:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556625082; bh=eKieE7if2lMhvvOxMlLJaaNlL71Am5r/lmbiTzC+8zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c4Rj94x8X0Tk80O3Oai1HjyhAjF65KwKeSuC9NZ9jgeBMXqDasz/5JMbbTjkn993B 6XkTfz8eLllrjNGrEueQO3LgEEXr/RK0ad4qdKMOHR16N0kuWbmABNebI8YZVYfehk +9ebfmH1n0685pIGB9bkshx9rE+qY8Tsl//IUGt4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tao Ren , Jakub Kicinski , Samuel Mendoza-Jonas , "David S. Miller" Subject: [PATCH 5.0 83/89] net/ncsi: handle overflow when incrementing mac address Date: Tue, 30 Apr 2019 13:39:14 +0200 Message-Id: <20190430113613.686303493@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tao Ren [ Upstream commit 1c5c12ee308aacf635c8819cd4baa3bd58f8a8b7 ] Previously BMC's MAC address is calculated by simply adding 1 to the last byte of network controller's MAC address, and it produces incorrect result when network controller's MAC address ends with 0xFF. The problem can be fixed by calling eth_addr_inc() function to increment MAC address; besides, the MAC address is also validated before assigning to BMC. Fixes: cb10c7c0dfd9 ("net/ncsi: Add NCSI Broadcom OEM command") Signed-off-by: Tao Ren Acked-by: Jakub Kicinski Acked-by: Samuel Mendoza-Jonas Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/etherdevice.h | 12 ++++++++++++ net/ncsi/ncsi-rsp.c | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -448,6 +448,18 @@ static inline void eth_addr_dec(u8 *addr } /** + * eth_addr_inc() - Increment the given MAC address. + * @addr: Pointer to a six-byte array containing Ethernet address to increment. + */ +static inline void eth_addr_inc(u8 *addr) +{ + u64 u = ether_addr_to_u64(addr); + + u++; + u64_to_ether_addr(u, addr); +} + +/** * is_etherdev_addr - Tell if given Ethernet address belongs to the device. * @dev: Pointer to a device structure * @addr: Pointer to a six-byte array containing the Ethernet address --- a/net/ncsi/ncsi-rsp.c +++ b/net/ncsi/ncsi-rsp.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -667,7 +668,10 @@ static int ncsi_rsp_handler_oem_bcm_gma( ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN); /* Increase mac address by 1 for BMC's address */ - saddr.sa_data[ETH_ALEN - 1]++; + eth_addr_inc((u8 *)saddr.sa_data); + if (!is_valid_ether_addr((const u8 *)saddr.sa_data)) + return -ENXIO; + ret = ops->ndo_set_mac_address(ndev, &saddr); if (ret < 0) netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");