From patchwork Mon Oct 12 15:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1381000 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=tm3V+zVe; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C932758yqz9sT6 for ; Tue, 13 Oct 2020 02:46:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=cO8Tu2dUJ+nJRoNw5C2iZjg9742d41Y3+9NoH6sonTw=; b=tm3V+zVeD1NKPuSBXg4ofRGQ3i ojRxEL5olJlPouZ7f7eRn+91TjSqbhimQKqiJlqaVGvFAI2og/HB0VX2OR2jU4jICcScHUgQRMLC1 z4OhSUVZX0TynfRqbz7L4o9SEE8AJrvSQbhc8hrRp63kj6sr+Azi7mmT3+wxXY6TwKEEUM92YL+hP b0P4FFxa4F5ow6XLwd7a8ZVfaLQ/Beb9GdeKWh+s4NynMtTdLEZzkr1TEiDih80PsjGrpa5rEUQ2N qpz/gsAFZWfLWS3yKxgSEM8tFYkvOcWYfa3KxedECSG3wTHDQ6cghyR9t9DlJaNDnKtmhw+L7yCic hPWc98XQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kS00N-0003BJ-Hk; Mon, 12 Oct 2020 15:44:55 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kS00J-0003A3-VT for openwrt-devel@lists.openwrt.org; Mon, 12 Oct 2020 15:44:53 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 989893D30; Mon, 12 Oct 2020 17:44:49 +0200 (CEST) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 003ec4f6; Mon, 12 Oct 2020 17:44:31 +0200 (CEST) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH mdnsd] cache: cache_record_find: fix buffer overflow Date: Mon, 12 Oct 2020 17:44:41 +0200 Message-Id: <20201012154441.6106-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201012_114452_164128_EB3E008F X-CRM114-Status: GOOD ( 18.62 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Fixes following buffer overflow: ERROR: AddressSanitizer: global-buffer-overflow on address 0x0000007338b8 at pc 0x0000004db339 bp 0x7ffe370e6140 sp 0x7ffe370e6138 READ of size 8 at 0x0000007338b8 thread T0 #0 0x4db338 in cache_record_find mdnsd/cache.c:197:17 #1 0x4d74b4 in cache_answer mdnsd/cache.c:336:6 #2 0x4cf04a in parse_answer mdnsd/dns.c:343:3 #3 0x4cb272 in dns_handle_packet mdnsd/dns.c:442:7 #4 0x4f508c in read_socket4 mdnsd/interface.c:253:3 #5 0x7fb81dddc73d in uloop_run_events libubox/uloop.c:198:4 #6 0x7fb81dddc73d in uloop_run_timeout libubox/uloop.c:555:3 #7 0x4c77cd in uloop_run libubox/uloop.h:111:9 #8 0x4c7757 in main mdnsd/main.c:99:2 0x0000007338b8 is located 8 bytes to the right of global variable 'records' defined in 'mdnsd/cache.c:45:1' (0x733880) of size 48 SUMMARY: AddressSanitizer: global-buffer-overflow mdnsd/cache.c:197:17 in cache_record_find Signed-off-by: Petr Štetiar --- cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.c b/cache.c index 7d2aa8fdba2d..b2e5568f517a 100644 --- a/cache.c +++ b/cache.c @@ -194,7 +194,7 @@ cache_record_find(char *record, int type, int port, int rdlength, uint8_t *rdata if (!l) return NULL; - while (l && l->record && !strcmp(l->record, record)) { + while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, record)) { struct cache_record *r = l; l = avl_next_element(l, avl);