Received: by 2002:a17:504:7599:b0:1be7:c013:c773 with SMTP id j25csp2066662njm; Tue, 2 Jul 2024 09:18:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWT6hnNdjyzwHBolwYzT72v5XM6m1P+V6lhtoEwIeFsBOWTx9S4gto9C9SlURQie3YM1FWJNPpw2eaEmUF7YJSq+RKxDkNy X-Google-Smtp-Source: AGHT+IEbglncz5k6Te5/XOEgVIJM2fwpp4z62a8k+k9qZOmhpPjuo/rX/AelAz8C0125Vc2h/cm5 X-Received: by 2002:a05:622a:1882:b0:446:50cc:2e68 with SMTP id d75a77b69052e-44662e5a381mr107580561cf.30.1719937111190; Tue, 02 Jul 2024 09:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719937111; cv=none; d=google.com; s=arc-20160816; b=BA5Z7PTpiVyYkTiVXmYux8wjFgLV/tdYed87+bbG0oOUO0bZaQEUqR4QJGI5/qUyCh 5Tp7RmT8nnqfLrxqSHWAFm5cBOsIYClWj4KGB4udPcaePNGFiZ4ziZ4+xx0ULHrV/yrO vaC9QjMGUT5HTDCl39kUHzPJJijW8ALq8qrtP44qJi+SwxNmAhsVJuqRN8qBNQRk9GQ1 Cj0rMvRI1LOzRtuL5Tn2rhXynw3r7d19gTda/kzIL1WvT/xcmEFSeHNKI87QkZc0jnBz psQQlULvUCqcOeNjozxJNyB5YTl7KtyLx62EiJSG/nlv3dk9erGAOWPFgA2tQRHgx+TP WPDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=NCg2q3ThYi6t48SlSLzReQHBySneepMMuzN9PiMJAD8=; fh=vEhJ0w1cTOCYHff2NU9W09NoerGREUgzrcwmmENVr0I=; b=i6CRzyElnkmyaO1nMorp9byHID46FyHFE6lv2ariZpAktrozGCTZkox3rqR1+1R669 y1m5zixi0hJCj3nhKlHQyNmjCx3DZQJcAQhjHmbdKzysWGObxlnoM5WPTVq5blhwJjd0 Y0MKdy5Gzy7xLgDx2Iz/mDp85Yh11d3pIKIjqlsnDG9DJG01mlj3a1DGvWDzJEvZPUJV 3rKkIZkJqFfU7fcU7Z8yKEOxIvkyZp2Ic1KwpXJi5hGs3OZQ6iRGkPThC6aYYTgqMRmG fXMJ5zpFHnRfVXnzndj91cb3AUn0Ig8+WPHmo817YqsvJYf7Q1/Rs2dzIHIZ/A+/aIeT KZsg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="HEf/jFfk"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-44667c2263bsi77420371cf.222.2024.07.02.09.18.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2024 09:18:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="HEf/jFfk"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOgCv-0003TL-RP; Tue, 02 Jul 2024 12:18:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOgCt-0003Rt-2Z for qemu-arm@nongnu.org; Tue, 02 Jul 2024 12:18:15 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOgCq-0001mp-Cb for qemu-arm@nongnu.org; Tue, 02 Jul 2024 12:18:14 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3678f36f154so187823f8f.2 for ; Tue, 02 Jul 2024 09:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719937089; x=1720541889; darn=nongnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=NCg2q3ThYi6t48SlSLzReQHBySneepMMuzN9PiMJAD8=; b=HEf/jFfkP7rocUBFca4MALM9CmG3RkFlanKgtF/YQQdbfwhkmU3srlsouXPg4F2DK1 XzphHW9JH6dBo8GhwW1pQGvRblPGI9O/gaU4bB2Ywuu21JuFtJy6mUHmXZtHhC1YZuBj hhC7aMnnLJBadbsSqI5/iDF9thhp/D5Hl7fdCQIOdgA1ZRH8w7GZDV+cLJCrcJM1tuzU VG8NytWjSeGfKkAYb02LcGEkzGOUwcAPkuyeIR8uRbZzayqaCZLBTMQ1XCmY77MaCFK1 jfMWHgH5grnueTiHCN06p8J9MULuZZNVIT+WIaBIR0dka1/4YZDmOfAuKnNZEITVRdX4 qLBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719937089; x=1720541889; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NCg2q3ThYi6t48SlSLzReQHBySneepMMuzN9PiMJAD8=; b=TcEY51s6RM0bXtp0oNICvi9nbg0pNlpiFTLHE9AGOweMRGyfY7FBHbPDEf1jB4p4BR pNxXV5orG6+hG9A+wRDwzHad55/M5P00vfYRfAroicrwBR83+fqbic8ZnnbibALun5a8 9oOJhuWFoxN6BvKCvdPtJwPS0nDGWUES0mi5ASW5JQwlD0D93hPdu9Z85PLFJEy0pD7f LU1dq57LaEob2Y+cnVplt/vX0LXJHy7hca9iqQjf2Newe9KItjQe6WA439JNM4/Ryp6I aOBkMqojBLR0vekkpfTXUXzB3AgEChZsp93/q8gTfkQYW/ydfXFxXzKT9AK5E0Z1ZbvZ AtkQ== X-Gm-Message-State: AOJu0YxHcTdu7THDkPhccymYubsI0E49uffLhFb3reTwmY4iL9viT70U Gx0fT2Hp/IOJuvNZWHmaKDMDBXsgWBFmWdsvX/R7SmeG6ugmhgLWJPoKauk0bk4= X-Received: by 2002:a5d:6890:0:b0:360:9436:b928 with SMTP id ffacd0b85a97d-367756aae29mr6369264f8f.27.1719937089209; Tue, 02 Jul 2024 09:18:09 -0700 (PDT) Received: from [192.168.69.100] ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0fba38sm13621997f8f.77.2024.07.02.09.18.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Jul 2024 09:18:08 -0700 (PDT) Message-ID: <8aa595ef-efb2-45f8-a89f-9a4db3b2f11e@linaro.org> Date: Tue, 2 Jul 2024 18:18:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] hw/char/pl011: Avoid division-by-zero in pl011_get_baudrate() To: Zheyu Ma , Peter Maydell , =?UTF-8?Q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org References: <20240702155752.3022007-1-zheyuma97@gmail.com> Content-Language: en-US From: =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= In-Reply-To: <20240702155752.3022007-1-zheyuma97@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: hKkwMbeASyex On 2/7/24 17:57, Zheyu Ma wrote: > In pl011_get_baudrate(), when we calculate the baudrate we can > accidentally divide by zero. This happens because although (as the > specification requires) we treat UARTIBRD = 0 as invalid, we aren't > correctly limiting UARTIBRD and UARTFBRD values to the 16-bit and 6-bit > ranges the hardware allows, and so some non-zero values of UARTIBRD can > result in a zero divisor. > > Enforce the correct register field widths on guest writes and on inbound > migration to avoid the division by zero. > > ASAN log: > ==2973125==ERROR: AddressSanitizer: FPE on unknown address 0x55f72629b348 > (pc 0x55f72629b348 bp 0x7fffa24d0e00 sp 0x7fffa24d0d60 T0) > #0 0x55f72629b348 in pl011_get_baudrate hw/char/pl011.c:255:17 > #1 0x55f726298d94 in pl011_trace_baudrate_change hw/char/pl011.c:260:33 > #2 0x55f726296fc8 in pl011_write hw/char/pl011.c:378:9 > > Reproducer: > cat << EOF | qemu-system-aarch64 -display \ > none -machine accel=qtest, -m 512M -machine realview-pb-a8 -qtest stdio > writeq 0x1000b024 0xf8000000 > EOF > > Suggested-by: Philippe Mathieu-Daudé Peter, feel free to replace that line by: Reviewed-by: Philippe Mathieu-Daudé > Suggested-by: Peter Maydell > Signed-off-by: Zheyu Ma > --- > Changes in v3: > - Defined masks for UARTIBRD and UARTFBRD to avoid magic numbers. Thanks Zheyu! > Changes in v2: > - Enforce the correct register field widths on writes to both UARTIBRD > and UARTFBRD registers. > - Mask UARTIBRD to 16 bits and UARTFBRD to 6 bits in the pl011_post_load > function to prevent division by zero during inbound migration. > --- > hw/char/pl011.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-)