github / github/codeql

[CPP][Questions]No effective API to qeury macro used in function parameter declaration

Ouverte
#8,497 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
C++ question
Langage dominant
CodeQL
Étoiles
10.1k
Forks
2.1k
Merge moyen
2 j 15 h
PR mergées (30 j)
141

Description

Hello all,

Recently I'm interested in writing queries to detect common vulnerability pattern specific for Linux kernel codebase. I find that `__user` marco is used to indicate parameter is user mode pointer, for example
```cpp
#define __user //empty macro body

static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode,
struct scsi_ioctl_command __user *sic) //sic is a user mode pointer
```

I want to write a query to get all user mode pointer defined in function parameter declaration, I tried to find avaliable API defined in `Marco/MacroAccess/MarcoInovation/Function/Function/FunctionDeclarationEntry/ParameterDeclarationEntry`, but I can not find one can be used for my purpose.

I have no way but to query macro used in function parameter declaration by combining `MacroAccess` and `Location`, the following code may be work, but it prone to be false positive and ugly:(

```ql
class UserParameterDeclarationEntry extends ParameterDeclarationEntry{
UserParameterDeclarationEntry(){
exists(MacroAccess m|
m.getMacroName() = "__user"
and m.getFile() = this.getFile()
and m.getLocation().getEndLine() = this.getLocation().getEndLine()
)
}
}
```

So I hope you guys can be kind enougth to help me find a more effective way to query specific macro in function parameter declaration, thank you:)

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

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