Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp719500ybh; Tue, 21 Jul 2020 06:24:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0TTjO9hhanwhu4swAuTP2JdKisSRgddQgIH3mzum5049NP5r1OPDeTkI6uxuXpxjrPtxf X-Received: by 2002:a05:6402:234b:: with SMTP id r11mr26413693eda.5.1595337885925; Tue, 21 Jul 2020 06:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595337885; cv=none; d=google.com; s=arc-20160816; b=tkMerfWJXNGfXPxKip9CvCsLWHLW7no1muOurEbSd81Nfi7QShT4nF4if3kpc2JKLg njHj3i9B48vuzcqPpGvsTPIAdmVwsrpezMEbD0ALDp8ke6zgyQ6KEgQ4kympk8zDweSd mhkXFqkxaCOSOqI2lLUeselM/NDPk/KMDHSzztH1xgHoHGIsBING9n/Wr/aXmwuXMLIu oJARDxtqQw0kb8bKD0/6LO9j6F9f8AHEwcJB0cClI8pA90QZmXQlhKJ560Bub2GezbGP isjd1pGkX/1paTgNQbc6QnKLL4ONAurgMIoB80wDPbMwNv2APo5MEuRoMOrrj2ghUzmg Mkow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wgx4z/DNiLcnwiVMTxlKfTLr89BUcZAmWBACQY4L4M0=; b=0k6gOcUySN6Eap7/c0lgh56L8U6RQnKy7C09DMmX2tttoyAokL9uZ4/aAwbkYHJTzJ dNpXoJqu0s7KcEz6T7KlEXEsK+z3G+ayx8bjUZup3AeeftxJd9GRBB7C8h75W65S1Lxd OUVJfoZT35MNL4pJnhhnz0RLbK2JQR+Wc5YdU7U7DkSNcNc9lqU0HBBFvCzXm+6GycrB /MQ6X4pcvS4/PuTyei5awfzwDU5p5EAexapLJURoaHovO9yesuKy27eyF3I20+OjzEMb ye9Eyo2F/GULvt8ExYSEA7LbEZU6k5t9AKE2UAbD7UbfckXbTUTrdrgZ1hDIL04vopPc t7Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=IPtVjYH+; 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=REJECT sp=REJECT dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cm19si12014517edb.529.2020.07.21.06.24.21; Tue, 21 Jul 2020 06:24:45 -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=@android.com header.s=20161025 header.b=IPtVjYH+; 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=REJECT sp=REJECT dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726769AbgGUNYJ (ORCPT + 99 others); Tue, 21 Jul 2020 09:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbgGUNYI (ORCPT ); Tue, 21 Jul 2020 09:24:08 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FE5AC0619DA for ; Tue, 21 Jul 2020 06:24:08 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id x9so10266195plr.2 for ; Tue, 21 Jul 2020 06:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wgx4z/DNiLcnwiVMTxlKfTLr89BUcZAmWBACQY4L4M0=; b=IPtVjYH+4Nl8qj0o4aNFzWOBc8gf/CsNkxwtrKnuV97gpBAP4vQDUvLkQhnl/IymTK qyrj6NZsozQP5Wh/LB1GqxnSVUNnrZSRjmS0UNg0wdO+LwaSWuPW/IrZzsUVvFijySMZ AJrAX6iI9Y9L+5VfYYMwZwp54BEJS6i+9oEXI4QN7H5MtWV12OoJ3+Z+X3K8yi17KoAS M1NbO1LfhHiuyYXkMhpV5eaJX6WcjB0wIR9BmSOT9vE+4WxTdBTQQPnK9ACUaw/iQCSz EtkaRQ4W3XJ/ZjhPgeDdmPyNX4RCtriRD4ABulFJj0/ngeXIVCqyb+NoojM9cEuXXZ22 38vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wgx4z/DNiLcnwiVMTxlKfTLr89BUcZAmWBACQY4L4M0=; b=dfFfcKB4l9xvKA5YMfWQmUuLAMY+pw3Ycogb0neydXoTJlgqCa2bJq8WCtMdyj2aN5 H6QbHuDdAelORl82I6OW42TDFzr/wr/tOXg5BAWIQ6X2/tACunxMzqB2Li0ivQr+5PJT 7BW/4UZoqywBWiiNvMDy9V0hX3aBJ7yGMam+iorEuMlml0fV0pxTaUwFCBD4ql+rLZL1 QeZmOFIrjgRFNtChTAeyOSmvmllLyXIFGKjM3BV+htAeo5tV0I/3YLZzfh6Dl1e30pFD komHn6QcJ/QLqe0plVQPKrf9CpxmkpMMTKDAjg3ejU/Dw0JKkmBrmxqouBwqKMgY6NNh Tsag== X-Gm-Message-State: AOAM533xfTyKXtiWwlyLn+V77Y1a+66GLE4m2QqzYeF02AbTajrssEoB Q5Y8Yyv1T+qXEvZkwaKpFJ3mBmj07WQ= X-Received: by 2002:a17:90a:a78b:: with SMTP id f11mr4608489pjq.42.1595337847865; Tue, 21 Jul 2020 06:24:07 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([2620:15c:211:0:4a0f:cfff:fe35:d61b]) by smtp.gmail.com with ESMTPSA id c207sm20291090pfb.159.2020.07.21.06.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 06:24:07 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, Mark Salyzyn , netdev@vger.kernel.org, Steffen Klassert , Herbert Xu , "David S. Miller" , Jakub Kicinski Subject: af_key: pfkey_dump needs parameter validation Date: Tue, 21 Jul 2020 06:23:54 -0700 Message-Id: <20200721132358.966099-1-salyzyn@android.com> X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In pfkey_dump() dplen and splen can both be specified to access the xfrm_address_t structure out of bounds in__xfrm_state_filter_match() when it calls addr_match() with the indexes. Return EINVAL if either are out of range. Signed-off-by: Mark Salyzyn Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: kernel-team@android.com --- Should be back ported to the stable queues because this is a out of bounds access. net/key/af_key.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/key/af_key.c b/net/key/af_key.c index b67ed3a8486c..dd2a684879de 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -1849,6 +1849,13 @@ static int pfkey_dump(struct sock *sk, struct sk_buff *skb, const struct sadb_ms if (ext_hdrs[SADB_X_EXT_FILTER - 1]) { struct sadb_x_filter *xfilter = ext_hdrs[SADB_X_EXT_FILTER - 1]; + if ((xfilter->sadb_x_filter_splen >= + (sizeof(xfrm_address_t) << 3)) || + (xfilter->sadb_x_filter_dplen >= + (sizeof(xfrm_address_t) << 3))) { + mutex_unlock(&pfk->dump_lock); + return -EINVAL; + } filter = kmalloc(sizeof(*filter), GFP_KERNEL); if (filter == NULL) { mutex_unlock(&pfk->dump_lock); -- 2.28.0.rc0.105.gf9edc3c819-goog