Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2124191ioo; Mon, 23 May 2022 10:35:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD9VuYAai5bqk0KjxRAFAUc2RcFw0z7YOQa3Ws0fLxAzE9h9zWh/uj3rMgKB6wLGRtNKR9 X-Received: by 2002:a17:902:c612:b0:161:e095:8ff6 with SMTP id r18-20020a170902c61200b00161e0958ff6mr21287788plr.145.1653327298438; Mon, 23 May 2022 10:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653327298; cv=none; d=google.com; s=arc-20160816; b=hG2FyxY/clXRm69qtJ4PKNvblKlH3DfclRcQhB/nPGKKa4xhFhJMJ/jDXMcbj2BD1c XItukmNlmZTV6fQiFjSDH8FnjmCoV5pNkliqTgNVWZqys97bukF+y9z22TZJiGkuASvQ JKnmyVjZ7DsUOVmHw94Trr31cLaCuQySGXgZH7b/Lj+Nc8rqPpFigTduXWTEBg8kjcLd 1uVdDikOQfDQUEyQiHaN/cYyqDyvJY2bP1h8NU/HtTMU6B9MUaZX3RUB2ye8Q60Nu41V VGwsauvhRtFWhUIuRzD/rhsNPbcDXWmT+9TKAkM1HNkBBZBtwhE58fuYd6pCaN4eDAFI J0/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CeooAe6Yz/Xv5rYeXy0GzB9RCQyglY9fZjaMKnO7TU4=; b=Lfkf6LZHY01hpc3Oi9YdM3tOzyJ5U8hdGD92gWXVBAVfvMCkMXBkhAHPGVcfhfc+O1 CLgBtJDx0zhz4F4QNCRYdZSCig03hEi1Tqcx/CIfNktrFyhjpEV40PZo9lxWZrYrfRfj n2ExJJhBnSsy2FawrRsthRPxy8qNEqxf8DihgRUU9ovrh3zokQZ6snLcq4FFErVygdDF vv6FLUQP6VSZJhi0U16zAVDfaINUtVysLmyJBx7FdhukckDGPXNARH2coEdjDQvFmn0K kmdoZzZ8vaLjOVoK4ulYZnI0+aIrUKALg378gyyzG7UW1HZ3VAZs6bhF9PPe3KCyT57O o9Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y0mALqeZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x11-20020a170902ec8b00b0015ad8a424e3si11802747plg.428.2022.05.23.10.34.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:34:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y0mALqeZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 55F13986E9; Mon, 23 May 2022 10:33:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241925AbiEWRbk (ORCPT + 99 others); Mon, 23 May 2022 13:31:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241695AbiEWRWd (ORCPT ); Mon, 23 May 2022 13:22:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 259F17C15B; Mon, 23 May 2022 10:19:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BB663B811FF; Mon, 23 May 2022 17:18:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02B39C385AA; Mon, 23 May 2022 17:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326281; bh=qWn9ZKbQrzQkwnnfeCk8yx1PqGXI3vpJJRoBj0bQd+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y0mALqeZRgObc+e1x2vbpeMx6r8EsoX/EM6uJ6rb88N9SPAEaGT5wAFoe1APEoS/T JarLZ9I9ck1HDny9Ub6BLkn61WBqmdckQjznghgjPsX/d6XmPPwwe9cMBO4ZEM6J2k LBOPT49lmAvLWdVK4Oz91XfzMOLvW9ccGvRjABE0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minh Yuan , Linus Torvalds , Denis Efremov , Willy Tarreau , Linus Torvalds Subject: [PATCH 5.15 003/132] floppy: use a statically allocated error counter Date: Mon, 23 May 2022 19:03:32 +0200 Message-Id: <20220523165824.064053072@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165823.492309987@linuxfoundation.org> References: <20220523165823.492309987@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willy Tarreau commit f71f01394f742fc4558b3f9f4c7ef4c4cf3b07c8 upstream. Interrupt handler bad_flp_intr() may cause a UAF on the recently freed request just to increment the error count. There's no point keeping that one in the request anyway, and since the interrupt handler uses a static pointer to the error which cannot be kept in sync with the pending request, better make it use a static error counter that's reset for each new request. This reset now happens when entering redo_fd_request() for a new request via set_next_request(). One initial concern about a single error counter was that errors on one floppy drive could be reported on another one, but this problem is not real given that the driver uses a single drive at a time, as that PC-compatible controllers also have this limitation by using shared signals. As such the error count is always for the "current" drive. Reported-by: Minh Yuan Suggested-by: Linus Torvalds Tested-by: Denis Efremov Signed-off-by: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/block/floppy.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -509,8 +509,8 @@ static unsigned long fdc_busy; static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); static DECLARE_WAIT_QUEUE_HEAD(command_done); -/* Errors during formatting are counted here. */ -static int format_errors; +/* errors encountered on the current (or last) request */ +static int floppy_errors; /* Format request descriptor. */ static struct format_descr format_req; @@ -530,7 +530,6 @@ static struct format_descr format_req; static char *floppy_track_buffer; static int max_buffer_sectors; -static int *errors; typedef void (*done_f)(int); static const struct cont_t { void (*interrupt)(void); @@ -1455,7 +1454,7 @@ static int interpret_errors(void) if (drive_params[current_drive].flags & FTD_MSG) DPRINT("Over/Underrun - retrying\n"); bad = 0; - } else if (*errors >= drive_params[current_drive].max_errors.reporting) { + } else if (floppy_errors >= drive_params[current_drive].max_errors.reporting) { print_errors(); } if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC) @@ -2095,7 +2094,7 @@ static void bad_flp_intr(void) if (!next_valid_format(current_drive)) return; } - err_count = ++(*errors); + err_count = ++floppy_errors; INFBOUND(write_errors[current_drive].badness, err_count); if (err_count > drive_params[current_drive].max_errors.abort) cont->done(0); @@ -2241,9 +2240,8 @@ static int do_format(int drive, struct f return -EINVAL; } format_req = *tmp_format_req; - format_errors = 0; cont = &format_cont; - errors = &format_errors; + floppy_errors = 0; ret = wait_til_done(redo_format, true); if (ret == -EINTR) return -EINTR; @@ -2761,10 +2759,11 @@ static int set_next_request(void) current_req = list_first_entry_or_null(&floppy_reqs, struct request, queuelist); if (current_req) { - current_req->error_count = 0; + floppy_errors = 0; list_del_init(¤t_req->queuelist); + return 1; } - return current_req != NULL; + return 0; } /* Starts or continues processing request. Will automatically unlock the @@ -2823,7 +2822,6 @@ do_request: _floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format]; } else probing = 0; - errors = &(current_req->error_count); tmp = make_raw_rw_request(); if (tmp < 2) { request_done(tmp);