GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — AF_VSOCK sockets reject buffered SOL_SOCKET options · Issue #161657 · python/cpython

AF_VSOCK sockets reject buffered SOL_SOCKET options #161657

New issue
Copy link
New issue
Copy link
Open
#161658
Open
AF_VSOCK sockets reject buffered SOL_SOCKET options#161657
#161658
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-socketRelated to the socket, socketserver and selectors modulesRelated to the socket, socketserver and selectors modulestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@bvolpato
bvolpato
opened on Nov 9, 2026
Issue body actions

Bug report

socket.setsockopt() and socket.getsockopt() apply the VSOCK-specific integer handling to every option on an AF_VSOCK socket, including SOL_SOCKET options. This rejects valid buffered options such as SO_LINGER before calling the operating system.

The following reproducer uses an owned, unconnected Unix socket FD to exercise the Python family dispatch. It does not require a VSOCK device, a VM, or a connection:

import socket
import struct

with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as raw:
    linger = struct.pack('ii', 1, 0)
    raw.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, linger)
    with socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM, 0,
                       fileno=raw.detach()) as sock:
        for operation in ('get', 'set'):
            try:
                if operation == 'get':
                    result = sock.getsockopt(socket.SOL_SOCKET,
                                             socket.SO_LINGER, len(linger))
                else:
                    result = sock.setsockopt(socket.SOL_SOCKET,
                                             socket.SO_LINGER, linger)
                print(operation, repr(result))
            except (OSError, TypeError) as error:
                print(operation, f'{type(error).__name__}: {error}')

On Python 3.15.0:

get OSError: getsockopt string buffer not allowed
set TypeError: setsockopt() argument 3 for AF_VSOCK must be an int (got bytes)

On a debug build of main at 3dee86d70560329437c2e774a1a89a3c57b14119, the get error is the same and the set error is TypeError: argument must be int, not bytes.

The expected result is the packed linger value for get and None for set, as with the original Unix socket. The VSOCK branches in socketmodule.c check the socket family but not the option level. Restricting these branches to level == AF_VSOCK restores the ordinary SOL_SOCKET paths while keeping the existing 64-bit VSOCK buffer-option handling.

This is separate from #159561 and its merged PR #159610, which removed a redundant type check without changing the option-level dispatch. I have a focused fix and regression test ready.

CPython versions tested on:

3.15, 3.16, CPython main branch

Operating systems tested on:

Linux

This report and the proposed fix were prepared with AI assistance.

Linked PRs

  • gh-161657: Fix SOL_SOCKET options on AF_VSOCK sockets #161658

Activity

  1. aisk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-socketRelated to the socket, socketserver and selectors modulesRelated to the socket, socketserver and selectors modules
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Nov 9, 2026
  2. bvolpato
    added a commit that references this issue on Nov 9, 2026

    pythongh-161657: Fix SOL_SOCKET options on AF_VSOCK sockets

    3c34157
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-socketRelated to the socket, socketserver and selectors modulesRelated to the socket, socketserver and selectors modulestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.