Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp23544ybg; Mon, 27 Jul 2020 22:08:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBcnXDZpwvf3WFAsIEe/j55GBXC5Dp5CrDeG8f1iMhzt7l0HVYWD4m2fdSsZPTnCS8+LTS X-Received: by 2002:a17:907:94c9:: with SMTP id dn9mr23407832ejc.355.1595912891312; Mon, 27 Jul 2020 22:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595912891; cv=none; d=google.com; s=arc-20160816; b=m889ajHntufLDoEm0uBDAn1U0DRj5KpfqRE0gWlhEabpRMAdLS8OuFVeBXPH1HIOSH Tc+9BR9Q9gBFQLPQ2czRq7OZhoK9fonQ23wTkUegjqUOpRMVFv+264TwZVZIZ2xUPpAT NsywD2lBPp1NbabsNDvpnhiCkH6d1ss+T+fc7EQPdzMWZPwcMg01dzAic0/7QTnClq6B qWsPwq9HgztA0J8fmzwiqJhbXqoCnW//YbCC/mDoAqHXVfqVVCBuRZ8SzKAy/3Y8pu3r GHL3X2S6dypn7cgbUhAZIyhxsl8ZK5XRG8lpO5PPcXb2JB6TMoS1Zg88oOfTS6DD6JS8 9x2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=s01fqjNBAwKASBwXHOws490cL9Prse2lxSMW+pCTIao=; b=NEyL2LX34hkNHTiY6DY5aC9i8nYNjqBe2ZUb5f5T4zP/c8hvkWFFwI1gAdtwLQ4fwT 9w80B6L4tIeu1fF3SRsFcZNe6QpUtE5ShQ280WPFR+a9fiUPxpTIITXJHnM1wxAQ2D5h SXKJqIy+E9WkjF/qU02u1j9rjNbkTiY3q7QQMeFVNj0Ac4RBe3J+62mlUqPvCJA95nI0 i5NkH8BSogjGR/yWpS8IN8XpGcPnHt7uyjhT+SGxdEtwjgS80y1R+lBa2P0PeIxfpC36 nSs+V8XkssIrvhlU1DLvt5DNI6f6sRD6XirYb8884GGDDIqfx3b48MRWv5XbJUFiNp73 v6eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="GiEob/uU"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si6643310ejb.342.2020.07.27.22.07.48; Mon, 27 Jul 2020 22:08:11 -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=@kernel.org header.s=default header.b="GiEob/uU"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726581AbgG1FHe (ORCPT + 99 others); Tue, 28 Jul 2020 01:07:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:59362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbgG1FHe (ORCPT ); Tue, 28 Jul 2020 01:07:34 -0400 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 354B222B47; Tue, 28 Jul 2020 05:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595912853; bh=julnmZ6d99C3BH6F52UlRn44Ck82VwZ9mFMWkFSJq0E=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GiEob/uUATJb6NGdNXNRPIXJMwx5B1hmd89pvpgQ1A7bneO6GstY8d5UUx/Xzh3cX rTw+eqI8jlyDCvT8aDqgDW2shNnG1Ip+L41mIssxsr9WnhIF264dq+dfevQdECGoYd IBJsfXYE+eCnZir5jQMZr1HGV8XIwIL9uKm2aL48= Received: by mail-lj1-f176.google.com with SMTP id v4so10027279ljd.0; Mon, 27 Jul 2020 22:07:33 -0700 (PDT) X-Gm-Message-State: AOAM531IRPBcM5FuHh/WX+4DNE11SPB8Flpz+CfVAPSp3nHL0lUqSxul NOBpxK9RlF+XFYygNJR+LhqDqG64eWzHoOpNU3s= X-Received: by 2002:a2e:9996:: with SMTP id w22mr12656350lji.446.1595912851449; Mon, 27 Jul 2020 22:07:31 -0700 (PDT) MIME-Version: 1.0 References: <20200728022859.381819-1-yepeilin.cs@gmail.com> In-Reply-To: <20200728022859.381819-1-yepeilin.cs@gmail.com> From: Song Liu Date: Mon, 27 Jul 2020 22:07:20 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [Linux-kernel-mentees] [PATCH net] xdp: Prevent kernel-infoleak in xsk_getsockopt() To: Peilin Ye Cc: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Dan Carpenter , Arnd Bergmann , Greg Kroah-Hartman , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , KP Singh , linux-kernel-mentees@lists.linuxfoundation.org, Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2020 at 7:30 PM Peilin Ye wrote: > > xsk_getsockopt() is copying uninitialized stack memory to userspace when > `extra_stats` is `false`. Fix it by initializing `stats` with memset(). > > Cc: stable@vger.kernel.org 8aa5a33578e9 is not in stable branches yet, so we don't need to Cc stable. > Fixes: 8aa5a33578e9 ("xsk: Add new statistics") > Suggested-by: Dan Carpenter > Signed-off-by: Peilin Ye > --- > net/xdp/xsk.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index 26e3bba8c204..acf001908a0d 100644 > --- a/net/xdp/xsk.c > +++ b/net/xdp/xsk.c > @@ -844,6 +844,8 @@ static int xsk_getsockopt(struct socket *sock, int level, int optname, > bool extra_stats = true; > size_t stats_size; > > + memset(&stats, 0, sizeof(stats)); > + xsk.c doesn't include linux/string.h directly, so using memset may break build for some config combinations. We can probably just use struct xdp_statistics stats = {}; Thanks, Song > if (len < sizeof(struct xdp_statistics_v1)) { > return -EINVAL; > } else if (len < sizeof(stats)) { > -- > 2.25.1 >