From owner-freebsd-bugs@FreeBSD.ORG Fri Oct 24 11:40:02 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6538A1065680 for ; Fri, 24 Oct 2008 11:40:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 41DC78FC17 for ; Fri, 24 Oct 2008 11:40:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id m9OBe1YV034286 for ; Fri, 24 Oct 2008 11:40:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id m9OBe150034285; Fri, 24 Oct 2008 11:40:01 GMT (envelope-from gnats) Resent-Date: Fri, 24 Oct 2008 11:40:01 GMT Resent-Message-Id: <200810241140.m9OBe150034285@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mateusz Guzik Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E7094106567A for ; Fri, 24 Oct 2008 11:31:56 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id D58558FC0A for ; Fri, 24 Oct 2008 11:31:56 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id m9OBVu45051029 for ; Fri, 24 Oct 2008 11:31:56 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id m9OBVujn051028; Fri, 24 Oct 2008 11:31:56 GMT (envelope-from nobody) Message-Id: <200810241131.m9OBVujn051028@www.freebsd.org> Date: Fri, 24 Oct 2008 11:31:56 GMT From: Mateusz Guzik To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/128335: [patch][cpufreq] Missing call to sbuf_delete() in two sysctl handlers X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Oct 2008 11:40:02 -0000 >Number: 128335 >Category: kern >Synopsis: [patch][cpufreq] Missing call to sbuf_delete() in two sysctl handlers >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Oct 24 11:40:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Mateusz Guzik >Release: 8.0-CURRENT >Organization: >Environment: FreeBSD eternal 8.0-CURRENT FreeBSD 8.0-CURRENT #14: Mon Sep 15 17:38:51 CEST 2008 f@eternal:/usr/obj/srv/build/CURRENT/src/sys/ETERNAL i386 >Description: cpufreq_levels_sysctl and cpufreq_settings_sysctl do the following: sbuf_new(&sb, NULL, 128, SBUF_AUTOEXTEND); [..] sets = malloc(set_count * sizeof(*sets), M_TEMP, M_NOWAIT); if (sets == NULL) return (ENOMEM); So it's possible that these function will return without freeing sb. >How-To-Repeat: >Fix: Patch is attached. Patch attached with submission follows: --- sys/kern/kern_cpu.c.orig 2008-10-23 22:59:45.000000000 +0200 +++ sys/kern/kern_cpu.c 2008-10-23 23:00:57.000000000 +0200 @@ -919,8 +919,10 @@ /* Get settings from the device and generate the output string. */ count = CF_MAX_LEVELS; levels = malloc(count * sizeof(*levels), M_TEMP, M_NOWAIT); - if (levels == NULL) + if (levels == NULL) { + sbuf_delete(&sb); return (ENOMEM); + } error = CPUFREQ_LEVELS(sc->dev, levels, &count); if (error) { if (error == E2BIG) @@ -958,8 +960,10 @@ /* Get settings from the device and generate the output string. */ set_count = MAX_SETTINGS; sets = malloc(set_count * sizeof(*sets), M_TEMP, M_NOWAIT); - if (sets == NULL) + if (sets == NULL) { + sbuf_delete(&sb); return (ENOMEM); + } error = CPUFREQ_DRV_SETTINGS(dev, sets, &set_count); if (error) goto out; >Release-Note: >Audit-Trail: >Unformatted: