Bug 173002 - [net] data type size problem in if_spppsubr.c
Summary: [net] data type size problem in if_spppsubr.c
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Some People
Assignee: Zhenlei Huang
URL: https://reviews.freebsd.org/D47335
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-23 20:10 UTC by Jens Wiatrowski
Modified: 2025-01-14 11:16 UTC (History)
3 users (show)

See Also:


Attachments
file.diff (504 bytes, patch)
2012-10-23 20:10 UTC, Jens Wiatrowski
no flags Details | Diff
if_spppsubr.c.patch (365 bytes, patch)
2012-10-23 23:08 UTC, Eitan Adler
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Wiatrowski 2012-10-23 20:10:00 UTC
Because cmd in struct spppreq (/usr/include/net/if_sppp.h) is an int,
fuword32() should be used instead of fuword() in sys/net/if_spppsubr.c, line 5133, I think.

Fix: Apply the patch I've appended.
Or change the type of cmd in struct spppreq to unsigned long.

Patch attached with submission follows:
How-To-Repeat: Use /sbin/spppcontrol on a 64bit machine.
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2012-10-23 23:08:15 UTC
---------- Forwarded message ----------
From: Jens Wiatrowski <wiatro@gmx.net>
Date: 23 October 2012 16:40
Subject: Re: Re: kern/173002: data type size problem in if_spppsubr.c
To: Eitan Adler <lists@eitanadler.com>


        Hello Eitan,

>
>please send the output of "diff -u" (unified diff) - this makes it
>more likely someone will look at the patch
>
Attached.

        Regards

                Jens


-- 
Eitan Adler
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2012-10-30 15:10:40 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-net

Over to maintainer(s).
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:40 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 4 Andriy Voskoboinyk freebsd_committer freebsd_triage 2019-01-26 12:48:50 UTC
I have no clue which type is right here; return PR to the net@
Comment 5 Zhenlei Huang freebsd_committer freebsd_triage 2024-10-29 09:11:58 UTC
Actually user space `struct spppreq spr` is not explicitly zeroed [1], so `fuword() / fueword()` can read garbage into kernel space. I guess /sbin/spppcontrol will get error EINVAL occasionally on a 64bit platforms.

As this is an old report, not sure if the reporter Jens can confirm this.

1. https://cgit.freebsd.org/src/tree/sbin/spppcontrol/spppcontrol.c?h=stable/13#n63
Comment 6 Zhenlei Huang freebsd_committer freebsd_triage 2024-10-30 07:24:55 UTC
(In reply to Zhenlei Huang from comment #5)
Proposed fix https://reviews.freebsd.org/D47335 .
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-01-14 10:59:00 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=08ec14fecf6a93c0321c31ba1f0b04db6b888f16

commit 08ec14fecf6a93c0321c31ba1f0b04db6b888f16
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-01-14 10:56:49 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-01-14 10:56:49 +0000

    sppp: Fix getting wrong spppreq cmd from ioctl

    ifr->ifr_data is supposed to point to a struct spppreq. The first member
    cmd of struct spppreq is int type. It was pre-read via `fueword()` before
    a full fetching. Unfortunately an user space `struct spppreq spr` may not
    be zeroed explicitly, on 64bit architectures `fueword()` reads 64bit word
    thus the garbage (extra 4 bytes) may be read into kernel space (subcmd).

    Prior to f9d8181868ee, `subcmd` was declared as int and assigned from
    `fuword()` and was implicitly converted from long to int. On 64bit little
    endian architectures the implicitly conversion overflows (undefined
    bahavior) which happen to trash the garbage (the extra 4 bytes, high
    32 bits) and worked, but no luck on 64bit big endian architectures.

    Since f9d8181868ee `subcmd` was changed to u_long then there is no
    conversion so we end up mismatching `subcmd` with user space's `cmd`.

    It is also a bit hackish to get the value of cmd via `fueword()`, instead
    we refer to it directly from spr->cmd.

    This is a direct commit to stable/13 as sppp(4) no longer exists in main
    and stable/14.

    PR:             173002
    Reviewed by:    glebius (previous version)
    Fixes:  f9d8181868ee Fixed yet more ioctl breakage due to the type of ...
    Differential Revision:  https://reviews.freebsd.org/D47335

 sys/net/if_spppsubr.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Comment 8 Zhenlei Huang freebsd_committer freebsd_triage 2025-01-14 11:16:37 UTC
Fixed in stable/13.