Received: by 10.223.185.116 with SMTP id b49csp6401597wrg; Wed, 28 Feb 2018 08:49:06 -0800 (PST) X-Google-Smtp-Source: AH8x224Ue6FXi3Zj+1TFp9DwUq1KVn40uiXrMI0j+0VT1t8KJyaPaii92b0d6k2mG71z3miDVAT2 X-Received: by 10.99.113.75 with SMTP id b11mr14965896pgn.271.1519836546690; Wed, 28 Feb 2018 08:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519836546; cv=none; d=google.com; s=arc-20160816; b=x+A81YFricUP4Ohlx7OV6wtnaccCJMWNy9ICZatcwsRZdb8Sp8GRQ1yCc8Lg35YhK0 t6eAfy+Ue3eChZxOkQdC9ySCnIE2bs99Bu59ROThOPbndbMCB01RiAT3Ink2k+MAt2xk JBnfffiTxq5rFTg0KM8o40Yvw/506OhkkCiWKMCiHZDhyXpk5oJzVgftkg8wkMXOzzQt +CDaVBJe3N+6VDCb0+wcmVx+pmok7vY3HJWHuUvaHA7NUxAYfNUt2EqqJTtmZPBOnuyB 52hWHC+lMx3kd7aAQBfwVhv+2LyyuyWXGNsbOVP0M+vaMQgLoI2I5TezW2q35KRszRA2 D2WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=4P/lSpeZXBf95rHmGOu/AmHwMygXOIkZFRvUC2wUTdk=; b=wGOitYHg9Va7uPaZiUdUxETs1KjGrU0IH9MWqHXBbLmGZVXZMY6DAFMZ5qfCe8VWXe TewXPbXmvJBjP5abxuoNLxgU7vKghpGhrbzjhL3U63XudD3nWrCkUDD50gVBlCY6FiE1 rMufOrDRYJmKZBAEZYX65mW74fxSv57JWATkV8YjV63ayh2VnEfPvfOwaZ6cqV1b1fp5 Gi4OiE4ZvFOyVZexJoDnhTwdJSGPkzha0s1z9KUTk7FbF745uWoaRnBnM5MGnH6UTwyK DEZDqpZnT+Hku2yHwaXndxgQgxGpTD8LPz3MYdHB5s41jAOXMi4CwIDZU/QmXLfUlyk1 dzqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u27si1463263pfk.241.2018.02.28.08.48.51; Wed, 28 Feb 2018 08:49:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934323AbeB1P6z (ORCPT + 99 others); Wed, 28 Feb 2018 10:58:55 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34584 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934293AbeB1P6v (ORCPT ); Wed, 28 Feb 2018 10:58:51 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yr-0006Xh-Jy; Wed, 28 Feb 2018 15:22:29 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yi-0000AR-22; Wed, 28 Feb 2018 15:22:20 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Eric Biggers" , "Steffen Klassert" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 151/254] af_key: fix buffer overread in parse_exthdrs() In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 4e765b4972af7b07adcb1feb16e7a525ce1f6b28 upstream. If a message sent to a PF_KEY socket ended with an incomplete extension header (fewer than 4 bytes remaining), then parse_exthdrs() read past the end of the message, into uninitialized memory. Fix it by returning -EINVAL in this case. Reproducer: #include #include #include int main() { int sock = socket(PF_KEY, SOCK_RAW, PF_KEY_V2); char buf[17] = { 0 }; struct sadb_msg *msg = (void *)buf; msg->sadb_msg_version = PF_KEY_V2; msg->sadb_msg_type = SADB_DELETE; msg->sadb_msg_len = 2; write(sock, buf, 17); } Signed-off-by: Eric Biggers Signed-off-by: Steffen Klassert Signed-off-by: Ben Hutchings --- net/key/af_key.c | 3 +++ 1 file changed, 3 insertions(+) --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -513,6 +513,9 @@ static int parse_exthdrs(struct sk_buff uint16_t ext_type; int ext_len; + if (len < sizeof(*ehdr)) + return -EINVAL; + ext_len = ehdr->sadb_ext_len; ext_len *= sizeof(uint64_t); ext_type = ehdr->sadb_ext_type;