From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x225ttwZrhxVTRyyUh8mPZUsv72KmhoI2jsY4TUy40U1dkp9tN17ofC4BUwWtusQToscEmrzw ARC-Seal: i=1; a=rsa-sha256; t=1516610915; cv=none; d=google.com; s=arc-20160816; b=MmYDfMNQQEHf3Sf9IdrYfRPdVpv0OarYjarYnI9cQFmJn4QoGnNyGVW21XfMRjWve6 clBRRivUW395Yy6y3Zwan/SLtORJtvkGUIvowLYB/WROvcJJtB67vC+xI/ECM7irCjVj N8eIJ9qeb5U0Xktbl5ACq98s5VBUBPe4C8undDnXBsux6O77rVe8jb9Y1jSN5v6/W9cH 2Q4rf1TN3AbopQroOKJfxu8EUxiSJUzemJjxOhJVa6o11i0JJpjl/IWDTD1pVVbT9EXI i5H4e/DllYqESJUAVWx2pgJ00XwZ/AWOv4j5RzXEzsr9NDx+PIrybv+J0nJHUBcub9J9 dgug== 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=Cb8D0wnaQaUpb+4M8D3KTgwjGZbbQPTpgXXcQxK03DY=; b=LJ/APVLXsp4nPWtfcbywx7q6igHLXCgeXTPOijRbB9XeS2Lny/phT099UGvaSlBB0I /CyP0qPQGKL0t0nUrIj2VVsFECT2aWC+3wqrKtDQ2DWfC0TMx83KHj0PbIf9Pi5FilA6 NBnZDsSjN70IrXay7djacCreuElfOzrX9VAPBV4aiJ6eRYWXeFcGILMGvZWwdPG6tqNG L4k4nS4bhhiLUOHLNrCTdNqx7M7wRX4mE8gcWzO/2CytJE9qBJpI1K/UtZtAnoapGZkj Hwaa4aPRmaMkYa5YZFvsgtOGLxnavTRiOF2WZ0Q89O/hwqAToDUUisxlXnV2V0PTELp7 JcMw== 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.9 09/47] af_key: fix buffer overread in verify_address_len() Date: Mon, 22 Jan 2018 09:45:20 +0100 Message-Id: <20180122083926.182645858@linuxfoundation.org> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180122083925.568134913@linuxfoundation.org> References: <20180122083925.568134913@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?1590281807120461381?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.9-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));