Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3322687pxf; Mon, 15 Mar 2021 07:07:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9oIaL50BrwuX0iMXzrsn1uo5xrjN4FB2veMpW/wLvnl1/0A/HJn5nXm4pfEOo6IOdptdo X-Received: by 2002:a17:907:76bb:: with SMTP id jw27mr23652650ejc.366.1615817260703; Mon, 15 Mar 2021 07:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817260; cv=none; d=google.com; s=arc-20160816; b=YHvT8/uv9DYcD80HjhvbAy+DiqiY8kzsDUMsdHQnpBP6btUZUbybxtEDDH1OxgOiFH EtXITHqAWCeMlrYHE9uVWjh3OHEYlLwrNoSZI3+kaYs0RyAMWM2VM2YLfhHVd3pxGXWx lNtrlmWyo7zfbe3uFhYTKgsnhyU1oa/XyFC6e4u4OmKGw7XoPa21SBdHPK0BtLcb+3tT Sjgw3JWa1leo+H382f4EI+b1gMN+9kLhN++rt6gcstZ5pduCKV9QoswoRrv4RTsjvyrn Tdt42ZTHE1Rc84GkIwBnNQUhPUOGIuN1iSLjOm4DLkEwkE+9YYrkf5+yX7Hzw+XTwKrh 7stA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aDP9BUrsM0IOTBAwkzT81+yw9VC/r93JT703pHZR9Aw=; b=Z6nSlPHRuVd+F18bHvJ9HCspjmp6axM4tForD89dy/+7EmyK2ucQxDH0WD0wgsMB68 0PTclsWoeJsO3r8WRtcsY/gHZk4KYU+kstDEfcQOxSOXIRqNsBrQvbImrhbMJfv9Ybwq AaZ8FCB67foajdFArdQPCH9Oe4S4c3m5GiAqFuypf3p8Nw7CBGmjoa9+AnAKTFldcXMn w/KDCKf3ccZvAXm7BvSeqpwDG1ntpmQH0+W8Wlu56hn+IDBYr1dyZ46WJEnlmDg2ZeSW bbKbwGwVHmkqPYepW+KzclqJqeHruamVbObLnqDjhoVI9Au9wNRiEi4z631MDmG4wr2W mKdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UnM+xPIi; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id wn9si10254569ejb.491.2021.03.15.07.07.17; Mon, 15 Mar 2021 07:07:40 -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=@linuxfoundation.org header.s=korg header.b=UnM+xPIi; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232072AbhCOODo (ORCPT + 99 others); Mon, 15 Mar 2021 10:03:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:34068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231760AbhCON5L (ORCPT ); Mon, 15 Mar 2021 09:57:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 06C2E64F01; Mon, 15 Mar 2021 13:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816618; bh=i5kk/hM9hB1ybFBjKO9kXNeWoWRQ6eg16y6EqfJXVAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UnM+xPIiAhx2QllT9zRpxBi09JZ1P471G4mcuYqHWhgco8YyNfe2VpfMTIXCoVIAw BNZczvDyKwdp5dfHXeaqoUGuDQXckdpMhB5BTM+tru8SD6xJ9MGw3X6UjXy7xoY4K8 YawB1DX5SOA/Aucg1NKt5KwPhbsmSpvyZ4dae0yE= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , Dan Carpenter , Arjun Roy , Jakub Kicinski Subject: [PATCH 5.10 016/290] tcp: Fix sign comparison bug in getsockopt(TCP_ZEROCOPY_RECEIVE) Date: Mon, 15 Mar 2021 14:51:49 +0100 Message-Id: <20210315135542.489803245@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Arjun Roy commit 2107d45f17bedd7dbf4178462da0ac223835a2a7 upstream. getsockopt(TCP_ZEROCOPY_RECEIVE) has a bug where we read a user-provided "len" field of type signed int, and then compare the value to the result of an "offsetofend" operation, which is unsigned. Negative values provided by the user will be promoted to large positive numbers; thus checking that len < offsetofend() will return false when the intention was that it return true. Note that while len is originally checked for negative values earlier on in do_tcp_getsockopt(), subsequent calls to get_user() re-read the value from userspace which may have changed in the meantime. Therefore, re-add the check for negative values after the call to get_user in the handler code for TCP_ZEROCOPY_RECEIVE. Fixes: c8856c051454 ("tcp-zerocopy: Return inq along with tcp receive zerocopy.") Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Arjun Roy Link: https://lore.kernel.org/r/20210225232628.4033281-1-arjunroy.kdev@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3829,7 +3829,8 @@ static int do_tcp_getsockopt(struct sock if (get_user(len, optlen)) return -EFAULT; - if (len < offsetofend(struct tcp_zerocopy_receive, length)) + if (len < 0 || + len < offsetofend(struct tcp_zerocopy_receive, length)) return -EINVAL; if (len > sizeof(zc)) { len = sizeof(zc);