From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x227SuRY9f57rABxvLFpppikunn7KvgLbsualQlieM6CtjcAzBrghI8aZ0yEJEP/wY7Bcls1t ARC-Seal: i=1; a=rsa-sha256; t=1516611151; cv=none; d=google.com; s=arc-20160816; b=If6TqT6HkXPZ+JR92Aq31EQpPmHL6XOjC3mYCjre+diMlVkv8/A4bfwBvRvuneysrI SE4/p7j5wk63kKJaBjTpXtBvpsB2bOmPyM0Ysglftt/SYFyGxFsrsqwx97fFeYxhZLRW S9QcwWoEod0SUYqBuWw97pDNzOEl7SlVCZV8QTEyAS3l4qmJJf/zcHqQHhq3sjmoeRzF XDy3GaL5zREgcqhd/7GB+2FH6DVZ76Uwg+0kZjYCEjGtQUw7G0bo1G3ktExZOjfpeAVM 7w6Wg+m0BW6D+NfUYoQF/LZLH2A85MSvv4wj4ILd3TEh6xzQLBhtdjUlUzA2WoDdSp2a UfKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=M6ts4mR7AApEZyqin7ncs/cwCs4MI6L2iF6MPVQCz4o=; b=iJurdtG/PHAOuRfv45ddEF1OQxu/XKPPPzNXh9UakLhX2SXGnGP2YvcoZK1AiS/VYP o4Jo5sp9P1drCROTfS5MA4FSehToU5xFgzTPZx39mZP654uE83BhL6Hp1RSUVj2D5S4z LBllzXAkNjXouj0fSZBSsJg2Rn46Qe1j4MLkVeZkLpu8X6wRWieL77SZkT0KjPDcEO0l DPbaUd+SiCieXrLafzBojAGInz4g1aL3aHxiHi9fvTwUz9xUHn5cuJpn+X0YTWZ338M2 OVbo1LGVvKNufdM+8xvzbjik17BJGCO2kQpJoK1xCaandPhacqsobe3h0LoiJDXkct9E a5LQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Potapenko , Eric Biggers , Steffen Klassert Subject: [PATCH 4.14 25/89] af_key: fix buffer overread in verify_address_len() Date: Mon, 22 Jan 2018 09:45:05 +0100 Message-Id: <20180122083957.157500160@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083954.683903493@linuxfoundation.org> References: <20180122083954.683903493@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590281377007342439?= X-GMAIL-MSGID: =?utf-8?q?1590282054787057997?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit 06b335cb51af018d5feeff5dd4fd53847ddb675a upstream. If a message sent to a PF_KEY socket ended with one of the extensions that takes a 'struct sadb_address' but there were not enough bytes remaining in the message for the ->sa_family member of the 'struct sockaddr' which is supposed to follow, then verify_address_len() read past the end of the message, into uninitialized memory. Fix it by returning -EINVAL in this case. This bug was found using syzkaller with KMSAN. Reproducer: #include #include #include int main() { int sock = socket(PF_KEY, SOCK_RAW, PF_KEY_V2); char buf[24] = { 0 }; struct sadb_msg *msg = (void *)buf; struct sadb_address *addr = (void *)(msg + 1); msg->sadb_msg_version = PF_KEY_V2; msg->sadb_msg_type = SADB_DELETE; msg->sadb_msg_len = 3; addr->sadb_address_len = 1; addr->sadb_address_exttype = SADB_EXT_ADDRESS_SRC; write(sock, buf, 24); } Reported-by: Alexander Potapenko Signed-off-by: Eric Biggers Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/key/af_key.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -401,6 +401,11 @@ static int verify_address_len(const void #endif int len; + if (sp->sadb_address_len < + DIV_ROUND_UP(sizeof(*sp) + offsetofend(typeof(*addr), sa_family), + sizeof(uint64_t))) + return -EINVAL; + switch (addr->sa_family) { case AF_INET: len = DIV_ROUND_UP(sizeof(*sp) + sizeof(*sin), sizeof(uint64_t));