Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3287264rwi; Fri, 28 Oct 2022 19:22:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tZ2g03n24u2d/5bAmIDI7pYukeA4pV1B5AL3QbHWlEA7FSH1Sl5uBZepe/rzpkNDm26FK X-Received: by 2002:aa7:de0a:0:b0:462:d2a0:93a with SMTP id h10-20020aa7de0a000000b00462d2a0093amr2143103edv.275.1667010158572; Fri, 28 Oct 2022 19:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667010158; cv=none; d=google.com; s=arc-20160816; b=X4LsOjZHwsQkI7Lz4kljssO62mSu8+4Cr17YSlGiGqtOSeZbcLr76KbLTUaIxEYgLM am6ROViE6EsXwInGbeqJ35+O9YYqcAmj3o0dq1oWWanDGDt2xWdqcvGpJevbM15zGvfk gE9XA07uazQV+TKntjhtAeQqisZHug+LB2J99B6K6WkyZOiXbDHkMoP0kBa+SPyxB5GH /cprvjymvhxsU+rJwFPIXhyWMkHfGCAYjEym8+Z9GP/HFbwU30+wzmS0dTtQfYX3Ghdb nEwnSRcd1QbVhbAcHF6P/NuxhcAXK8nGYJ/Qfzc65M13sGZwXWLdsT1SCE4ciGg7gMP0 G/Sg== 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 :message-id:date:subject:to:from:dkim-signature; bh=kXrSw5CRFHg3ideg5TbwtiGG5a7qvoQu+xbgIOl14Io=; b=BIx+Vve/Da/2um7LI5R8Z2il2QwX6SsJ6k9V8WluZpNF3VwLHxJxRU5ppdvdk9p4ug mn3QERPJHY1ZJtqE6e12HEj+vLiI84/a/O35kYGExrHFUbbX8TXYyDhb+//UkH/Bcpw+ dKMH9qBtmVU0jlEnj7w5X506tMQ1P+r+m7Xq5XjVlTyhJkUHUdaSBjv3yl6WEuvFtxIY CsR17xxRgWvDID1lB/tDSbAKrIezGEzzkGHYsv+yDa/6tenRH/hkpn3iVFb89ne8fybB XdQ8zt/Ol1mP3S4bxAe9m0OuNM3UKN/PxPIHWnGAY1AbZvIiYxdWrpoqjUiTT/qa+NU1 mKeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@treblig.org header.s=bytemarkmx header.b=V6QYyT9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji7-20020a170907980700b0078e25345011si325661ejc.926.2022.10.28.19.21.53; Fri, 28 Oct 2022 19:22:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@treblig.org header.s=bytemarkmx header.b=V6QYyT9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229542AbiJ2Bqz (ORCPT + 99 others); Fri, 28 Oct 2022 21:46:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbiJ2Bqx (ORCPT ); Fri, 28 Oct 2022 21:46:53 -0400 Received: from mx.treblig.org (mx.treblig.org [46.43.15.161]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FF64226E4D for ; Fri, 28 Oct 2022 18:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=treblig.org ; s=bytemarkmx; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kXrSw5CRFHg3ideg5TbwtiGG5a7qvoQu+xbgIOl14Io=; b=V6QYyT9NL2DX56U/ep+qVZTb+y RDGqbssC2tMRc54A23xrI6W0vwgSLo/8n8thjLVk6lYcSDbVJVR+w1C/s03mv7+z7365ggfn7zuUL cd3Wf/qnOjpYr6o+tqFbUi/hOzdJKfK+8D21q6CWCcNmrlS4wGAM64IiGVSCpMT3/2KH7ALNmsUEj OW2SqeYrUVEQg3Sw6w5zIAeMW7YVxs3zbowb6eDe7BzpypNRVqQKgTrV4VxfucdPNbk0SM0vydhDd gL9OmCHFHdiW7RmtFQzs8/huo8Q5i4vOmfihijHA4YQZANC5BcikXAWzix2rbaRcL6WmSI6gtGYn8 ayllSOTg==; Received: from localhost ([127.0.0.1] helo=dalek.home.treblig.org) by mx.treblig.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ooavl-00ArpV-As; Sat, 29 Oct 2022 02:46:36 +0100 From: linux@treblig.org To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux@treblig.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: core: inet[46]_pton strlen len types Date: Sat, 29 Oct 2022 02:46:04 +0100 Message-Id: <20221029014604.114024-1-linux@treblig.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Dr. David Alan Gilbert" inet[46]_pton check the input length against a sane length limit (INET[6]_ADDRSTRLEN), but the strlen value gets truncated due to being stored in an int, so there's a theoretical potential for a >4G string to pass the limit test. Use size_t since that's what strlen actually returns. I've had a hunt for callers that could hit this, but I've not managed to find anything that doesn't get checked with some other limit first; but it's possible that I've missed something in the depth of the storage target paths. Signed-off-by: Dr. David Alan Gilbert --- net/core/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/utils.c b/net/core/utils.c index 938495bc1d348..c994e95172acf 100644 --- a/net/core/utils.c +++ b/net/core/utils.c @@ -302,7 +302,7 @@ static int inet4_pton(const char *src, u16 port_num, struct sockaddr_storage *addr) { struct sockaddr_in *addr4 = (struct sockaddr_in *)addr; - int srclen = strlen(src); + size_t srclen = strlen(src); if (srclen > INET_ADDRSTRLEN) return -EINVAL; @@ -322,7 +322,7 @@ static int inet6_pton(struct net *net, const char *src, u16 port_num, { struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; const char *scope_delim; - int srclen = strlen(src); + size_t srclen = strlen(src); if (srclen > INET6_ADDRSTRLEN) return -EINVAL; -- 2.37.3