From patchwork Thu Apr 13 19:42:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 9679941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B201F60326 for ; Thu, 13 Apr 2017 19:43:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A06DF24560 for ; Thu, 13 Apr 2017 19:43:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94E97286A4; Thu, 13 Apr 2017 19:43:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22E7924560 for ; Thu, 13 Apr 2017 19:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755737AbdDMTmz (ORCPT ); Thu, 13 Apr 2017 15:42:55 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:50945 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755604AbdDMTmy (ORCPT ); Thu, 13 Apr 2017 15:42:54 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3DJgg4e005697 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Apr 2017 19:42:42 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v3DJgfhR026227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Apr 2017 19:42:41 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v3DJgdZs003968; Thu, 13 Apr 2017 19:42:39 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 13 Apr 2017 12:42:38 -0700 Date: Thu, 13 Apr 2017 22:42:31 +0300 From: Dan Carpenter To: "David S. Miller" , Jens Axboe , Sagi Grimberg Cc: Wei Tang , Alexey Dobriyan , netdev@vger.kernel.org, linux-block@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH block-tree] net: off by one in inet6_pton() Message-ID: <20170413194231.GD591@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.0 (2016-04-01) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If "scope_len" is sizeof(scope_id) then we would put the NUL terminator one space beyond the end of the buffer. Fixes: b1a951fe469e ("net/utils: generic inet_pton_with_scope helper") Signed-off-by: Dan Carpenter Reviewed-by: Sagi Grimberg --- This one goes through Jens' tree not through net-dev. diff --git a/net/core/utils.c b/net/core/utils.c index da1089ea5389..93066bd0305a 100644 --- a/net/core/utils.c +++ b/net/core/utils.c @@ -339,7 +339,7 @@ static int inet6_pton(struct net *net, const char *src, u16 port_num, src + srclen != scope_delim && *scope_delim == '%') { struct net_device *dev; char scope_id[16]; - size_t scope_len = min_t(size_t, sizeof(scope_id), + size_t scope_len = min_t(size_t, sizeof(scope_id) - 1, src + srclen - scope_delim - 1); memcpy(scope_id, scope_delim + 1, scope_len);