From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9B52C43331 for ; Mon, 11 Nov 2019 19:04:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B33F922459 for ; Mon, 11 Nov 2019 19:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573499046; bh=q7GsNm40S/DiKtFTZ0JcwUyWixm0EX+jJcNR3wLwS98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wYwQm9w8KUnwrJae04mcJNVv0qty+Kx+LGv2nzjWROvNqu2sKXw+gfdtCDlB4+IAV UZxSAGo9zqs2ggmf7jP/2mYHaFZQr8mdxatrraDj3sO88+4H8Jkd9dKfr5gZ51iUdC F/MhYMXkzhIzwUsgTguRlS2653d8RwaeevbQ4LW8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728211AbfKKTEF (ORCPT ); Mon, 11 Nov 2019 14:04:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:34978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729644AbfKKSnf (ORCPT ); Mon, 11 Nov 2019 13:43:35 -0500 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 1B039204FD; Mon, 11 Nov 2019 18:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497815; bh=q7GsNm40S/DiKtFTZ0JcwUyWixm0EX+jJcNR3wLwS98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hjXxfJ0htm7NpOPbD7vAOBeFUCgk/ItMgCaRYS2y+HT3X/Ddg68PwYhM1/CoRqLCn j8WwcpEG+qb//N2U52xHHTYjbzI7XJQjZ6LwJnlKFl60IIiLcHz06/GlK8usrK9+Ix emVSoMbTmvUjTspNNz3HxnKLvhEhhAdqgVK5+GQs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jozsef Kadlecsik Subject: [PATCH 4.19 038/125] netfilter: ipset: Fix an error code in ip_set_sockfn_get() Date: Mon, 11 Nov 2019 19:27:57 +0100 Message-Id: <20191111181445.637037706@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181438.945353076@linuxfoundation.org> References: <20191111181438.945353076@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: Dan Carpenter commit 30b7244d79651460ff114ba8f7987ed94c86b99a upstream. The copy_to_user() function returns the number of bytes remaining to be copied. In this code, that positive return is checked at the end of the function and we return zero/success. What we should do instead is return -EFAULT. Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support") Signed-off-by: Dan Carpenter Signed-off-by: Jozsef Kadlecsik Signed-off-by: Greg Kroah-Hartman --- net/netfilter/ipset/ip_set_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/net/netfilter/ipset/ip_set_core.c +++ b/net/netfilter/ipset/ip_set_core.c @@ -1977,8 +1977,9 @@ ip_set_sockfn_get(struct sock *sk, int o } req_version->version = IPSET_PROTOCOL; - ret = copy_to_user(user, req_version, - sizeof(struct ip_set_req_version)); + if (copy_to_user(user, req_version, + sizeof(struct ip_set_req_version))) + ret = -EFAULT; goto done; } case IP_SET_OP_GET_BYNAME: { @@ -2035,7 +2036,8 @@ ip_set_sockfn_get(struct sock *sk, int o } /* end of switch(op) */ copy: - ret = copy_to_user(user, data, copylen); + if (copy_to_user(user, data, copylen)) + ret = -EFAULT; done: vfree(data);