[RISC-V/Linux] clock_nanosleep accepts an invalid clock ID

Ouverte
#1,683 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
66/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
c, linux, python

Piste de recherche

The bug is in the clock_nanosleep handler in qiling/os/posix/syscall/time.py, which the issue says ignores its clockid argument. Read that handler first, then build the probe.c guest with a RISC-V cross compiler and run it through Qiling to reproduce the zero-duration call with clockid 999. Done means clockid 999 returns -1 with errno EINVAL while CLOCK_MONOTONIC still returns 0.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Describe the bug

On an RV64 Linux guest, Qiling v1.4.11 returns success for clock_nanosleep with clockid=999. Linux returns EINVAL. A zero-duration request makes this a deterministic clock-ID validation case.

Sample Code
#define _GNU_SOURCE
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <sys/syscall.h>
#include <unistd.h>

int main(void)
{
    struct timespec req = {0, 0};
    long control = syscall(SYS_clock_nanosleep, CLOCK_MONOTONIC, 0, &req, 0);
    if (control != 0)
        return 2;
    errno = 0;
    long invalid = syscall(SYS_clock_nanosleep, 999, 0, &req, 0);
    int invalid_errno = errno;
    printf("control=%ld invalid=%ld errno=%d\n",
           control, invalid, invalid_errno);
    return !(invalid == -1 && invalid_errno == EINVAL);
}
mkdir -p rootfs
riscv64-linux-gnu-gcc -static -O2 probe.c -o probe.elf

Run the static RV64 guest with Qiling:

from qiling import Qiling

ql = Qiling(["./probe.elf"], "./rootfs")
ql.run()
Expected behavior

The valid CLOCK_MONOTONIC control returns 0. The invalid clock ID should return -1 with errno EINVAL. Qiling v1.4.11 returns 0 for both calls.

Additional context

Reproduced with Qiling v1.4.11. The current dev source was checked at commit 23ad4fd369a360ad7992d90cb7577f0241061c2b; that exact commit was not dynamically re-run. Its handler ignores clockid; see time.py. Linux documents EINVAL for an invalid clock ID in clock_nanosleep(2).

Langage dominant
Python
Étoiles
6.2k
Forks
806
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

  • Fournit un Dockerfile ou un fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de qilingframework/qiling

Toutes les issues de qilingframework/qiling

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.