NetBSD Problem Report #56962

From www@netbsd.org  Tue Aug  9 12:45:08 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 45EC11A9239
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  9 Aug 2022 12:45:08 +0000 (UTC)
Message-Id: <20220809124506.67C2C1A923A@mollari.NetBSD.org>
Date: Tue,  9 Aug 2022 12:45:06 +0000 (UTC)
From: ivan.buravlev@hotmail.com
Reply-To: ivan.buravlev@hotmail.com
To: gnats-bugs@NetBSD.org
Subject: Incorrect behavior of the devsw_attach function
X-Send-Pr-Version: www-1.0

>Number:         56962
>Category:       kern
>Synopsis:       Incorrect behavior of the devsw_attach function
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 09 12:50:01 +0000 2022
>Closed-Date:    Sun Aug 28 12:22:41 +0000 2022
>Last-Modified:  Sun Aug 28 12:22:41 +0000 2022
>Originator:     Ivan Buravlev
>Release:        MAIN src branch since Mar 28 12:33:32 2022
>Organization:
Kaspersky Lab
>Environment:
source code
>Description:
In sys/kern/subr_devsw.c:197 incorrect if-condition.

193	/*
194	 * If we already found a conv, we're done.  Otherwise, find an
195	 * empty slot or extend the table.
196	 */
197	if (i == max_devsw_convs)
198		goto out;

Function execution should be interrupted if conv is found. But i is equal to max_devsw_convs if conv is not found. Additionally, at the goto point, the error variable remains uninitialized.

>How-To-Repeat:

>Fix:
193	/*
194	 * If we already found a conv, we're done.  Otherwise, find an
195	 * empty slot or extend the table.
196	 */
197	if (i < max_devsw_convs) {
198		error = 0;
199		goto out;
200	}

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56962 CVS commit: src/sys/kern
Date: Sun, 28 Aug 2022 11:17:38 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sun Aug 28 11:17:38 UTC 2022

 Modified Files:
 	src/sys/kern: subr_devsw.c

 Log Message:
 devsw(9): Fix case of existing conv in devsw_attach.

 - Fix sense of conditional: if we found a conv, i < max_devsw_convs.
 - Make sure to initialize error on the way out.

 PR kern/56962: Incorrect behavior of the devsw_attach function


 To generate a diff of this commit:
 cvs rdiff -u -r1.46 -r1.47 src/sys/kern/subr_devsw.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sun, 28 Aug 2022 12:22:41 +0000
State-Changed-Why:
fixed, thanks!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.